psql

 16th December 2020 at 4:39pm

参考 PostgreSQL: Admin: General,使用 postgres 用户运行 psql。

退出:

postgres=# \q

列出用户:

postgres=# \du
                                      List of roles
    Role name    |                         Attributes                         | Member of 
-----------------+------------------------------------------------------------+-----------
 course          | Superuser                                                  | {}
 goodreads_clone | Superuser                                                  | {}
 postgres        | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

导入数据,用 \i,如 basics.sql

单步模式:psql -s。效果如下:

$ psql -s mydb
psql (12.3)
Type "help" for help.

mydb=# \i basics.source 
***(Single step mode: verify command)*******************************************
CREATE TABLE weather (
        city            varchar(80),
        temp_lo         int,
        temp_hi         int,
        prcp            real,
        date            date
);
***(press return to proceed or enter x and return to cancel)********************