PostgreSQL基本操作

1.导入sql文件到指定数据库

进入postgresql安装路径bin目录下:打开cmd
psql -d 数据库名 -h ip地址 -p 数据库端口 -U 用户名 -f 文件地址

2.启动postgresql并 进入超级用户postgres里

进入postgresql安装路径bin目录下,打开cmd,输入:psql -U postgres
,然后使用命令:“createuser odoo with superuser createdb createuser” 创建一个拥有超级用户,可以创建db,可以创建user的用户odoo


image
image
image
3.查看所有角色和权限
postgres=# SELECT * FROM pg_roles;
          rolname          | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcanlogin | rolreplication | rolconnlimit | rolpassword | rolvaliduntil | rolbypassrls | rolconfig |  oid
---------------------------+----------+------------+---------------+-------------+-------------+----------------+--------------+-------------+---------------+--------------+-----------+-------
 pg_signal_backend         | f        | t          | f             | f           | f           | f              |           -1 | ********    |               | f            |           |  4200
 admin                     | f        | t          | f             | f           | t           | f              |           -1 | ********    |               | f            |           | 85519
 pg_read_server_files      | f        | t          | f             | f           | f           | f              |           -1 | ********    |               | f            |           |  4569
 postgres                  | t        | t          | t             | t           | t           | t              |           -1 | ********    |               | t            |           |    10
 pg_write_server_files     | f        | t          | f             | f           | f           | f              |           -1 | ********    |               | f            |           |  4570
 pg_execute_server_program | f        | t          | f             | f           | f           | f              |           -1 | ********    |               | f            |           |  4571
 pg_read_all_stats         | f        | t          | f             | f           | f           | f              |           -1 | ********    |               | f            |           |  3375
 pg_monitor                | f        | t          | f             | f           | f           | f              |           -1 | ********    |               | f            |           |  3373
 pg_read_all_settings      | f        | t          | f             | f           | f           | f              |           -1 | ********    |               | f            |           |  3374
 pg_stat_scan_tables       | f        | t          | f             | f           | f           | f              |           -1 | ********    |               | f            |           |  3377
(10 行记录)
4.删除角色
postgres=# drop role admin;
DROP ROLE
5.创建具有超级管理员权限的用户
postgres=# CREATE ROLE admin superuser PASSWORD 'admin' login;
CREATE ROLE

你可能感兴趣的:(PostgreSQL基本操作)