PostgreSQL 删除重导数据库

  1. 强制kill数据库活动连接

    1
    dbname=# select pg_terminate_backend(pid) from pg_stat_activity where datname = 'dbname' and pid <>pg_backend_pid();
  2. 删除数据库

    1
    dbname=# drop database dbname;
  3. 新建数据库

    1
    dbname=# create database dbname;
  4. 授权给用户

    1
    dbname=# grant all privileges on database dbname to dbuser;
  5. shell命令行删除数据库

    $ dropdb -h localhost -p 5432 -U postgres dbname

  6. shell命令行导入数据库

    $ psql -h host -U postgres -d dbname < database_export.sql