PostgreSql数据库操作记录

参考:数据库名:govcloud_db_java

创建数据库:

服务器执行:
createdb -U postgres govcloud_db_java

或数据库登录后执行:
createdb govcloud_db_java

删除自带schema:

登录数据库
psql -U postgres
连接对应库
\connect govcloud_db_java
删除自带schema public
DROP 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-dump202002020101.backup

 

你可能感兴趣的:(大数据,postgresql)