创建数据库,注意创建之前要切换到对应的用户,这会影响到owned

CREATE DATABASE "test-db";

修改owned

REASSIGN OWNED BY oldowed TO newowned;

删除数据库

DROP DATABASE  "test-db";

清理所有连接

SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE datname='test-db' AND pid<>pg_backend_pid();

运行sql文件

\i /home/db_data.sql;

切换数据库

\c db name

切换用户

\c - user name

导入数据库

psql test-db < ~/test-db.sql;

导出数据库

pg_dump test-db > ~/test-db.sql;

创建普通用户
CREATE USER dbuser WITH PASSWORD 'xxxx'

超级用户

CREATE ROLE dbuser SUPERUSER PASSWORD 'xxxx' LOGIN;

修改数据名称
ALTER DATABASE "old name" RENAME TO "new name";