参考:数据库名:govcloud_db_java
创建数据库:
服务器执行:createdb -U postgres govcloud_db_java或数据库登录后执行:createdb govcloud_db_java
删除自带schema:
登录数据库psql -U postgres连接对应库\connect govcloud_db_java删除自带schema publicDROP SCHEMA public CASCADE;完成\q
删除数据库:
drop database govcloud_db_java
复制数据库前:断开所有访问用户
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'govcloud_test' AND pid <> pg_backend_pid();
复制数据库:
CREATE DATABASE govcloud_java WITH TEMPLATE govcloud_test OWNER postgres;
查看连接数:
show max_connections;SELECT COUNT(*) from pg_stat_activity;select min_val, max_val from pg_settings where name='max_connections';
数据库备份:
pg_dump --format=c -n "cms" -n "public" --verbose --host=localhost --port=5432 --username=postgres -f /home/database_backup/govcloud_db_java-dump$(date +"%Y-%m-%d,%H:%m:%s").backup govcloud_db_java
数据库恢复:
pg_restore --verbose --host=localhost --port=5432 --username=postgres --format=c --dbname=govcloud_db_java -1 \home\app\govcloud_db_java-dump0201.backup