postgresql客户端命令之createdb
创建一个新的PostgreSQL数据库。该命令的使用方式如下:
2.应用示例: [postgres@localhost PG_9.5_201510051]$ psql -p 36985 psql.bin (9.5.9) Type "help" for help. postgres=# [postgres@localhost PG_9.5_201510051]$ psql -U postgres -p 36985 postgres=# [postgres@localhost PG_9.5_201510051]$ psql -U postgres -d postgres -p 36985 postgres=# q
postgres=# CREATE TABLESPACE tbspace01 LOCATION '/data/postgresql/tbspace'; CREATE TABLESPACE [postgres@localhost tbspace]$ cd /data/postgresql/tbspace [postgres@localhost tbspace]$ ls PG_9.5_201510051 3. 创建新数据库的owner。postgres=# CREATE ROLE testwjw LOGIN PASSWORD '123456'; #4.创建新数据库,其中本次连接的登录用户为testwjw,新数据库的owner为testwjw,新数据库名为cstest01。 [postgres@localhost ~]$ createdb -U testwjw -p36985 -O testwjw -e cstest01 CREATE DATABASE cstest01 OWNER testwjw TABLESPACE db_space01; createdb: database creation failed: ERROR: permission denied to create database 原因是用户testwjw没有创建库的权限: postgres=# alter user testwjw createdb; ALTER ROLE postgres=# du List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- myuser | | {} postgres | Superuser,Create role,Create DB,Replication,Bypass RLS | {} testwjw | Create DB
5.重新登录,通过查询系统表查看该数据库是否创建成功,以及表空间和所有者是否一致。 postgres=# SELECT datname,rolname,spcname FROM pg_database db,pg_authid au,pg_tablespace ts WHERE datname = 'cstest01' AND datdba = au.oid AND dattablespace = ts.oid; datname | rolname | spcname ----------+---------+------------ cstest01 | testwjw | pg_default (1 row) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |