Use CreateUser to create a user
[Plain]View Plaincopyprint?
- [Email protected] ~]$/data/pgsql/bin/createuser--help
- CreateUser creates a new PostgreSQL role.
- Usage:
- CreateUser [OPTION] ... [ROLENAME]
- Options:
- -C,--connection-limit=n connection limit for role (Default:no limit)
- -D,--createdb role can create new databases
- -D,--no-createdb role cannot create databases (default)
- -E,--echo show the commands being sent to the server
- -E,--encrypted encrypt stored password
- -I,--inherit role inherits privileges of roles it is a
- Member of (default)
- -I,--no-inherit role does not inherit privileges
- -L,--login role can login (default)
- -L,--no-login role cannot login
- -N,--unencrypted do not encrypt stored password
- -P,--pwprompt assign a password to new role
- -R,--createrole role can create new roles
- -R,--no-createrole role cannot create roles (default)
- -S,--superuser role would be superuser
- -S,--no-superuser role won't be superuser (default)
- -V,--version output version information, then exit
- --interactive prompt for missing role name and attributes rather
- than using defaults
- --replication role can initiate replication
- --no-replication role cannot initiate replication
- -?,--Help show this help and then exit
- Connection options:
- -H,--host=hostname database server host or socket directory
- -p,--port=port database server port
- -U,--username=username user name to connect as (not the one to create)
- -W,--no-password never prompt for password
- -W,--password force password prompt
- Report bugs to <[email Protected]>.
- [Email protected] ~]$
- [Email protected] ~]$
- [Email protected] ~]$/data/pgsql/bin/createuser zhongwc-p
- Enter Password for new role:
- Enter It again:
- [Email protected] ~]$
Create a database using Createdb
[Plain]View Plaincopyprint?
- [Email protected] ~]$/data/pgsql/bin/createdb--help
- Createdb creates a PostgreSQL database.
- Usage:
- Createdb [OPTION] ... [DBNAME] [DESCRIPTION]
- Options:
- -D,--tablespace=tablespace default tablespace for the database
- -E,--echo show the commands being sent to the server
- -E,--encoding=encoding encoding for the database
- -L,--locale=locale locale settings for the database
- --lc-collate=locale lc_collate setting for the database
- --lc-ctype=locale lc_ctype setting for the database
- -O,--owner=owner database user to own the new database
- -T,--template=template template database to copy
- -V,--version output version information, then exit
- -?,--Help show this help and then exit
- Connection options:
- -H,--host=hostname database server host or socket directory
- -p,--port=port database server port
- -U,--username=username user name to connect as
- -W,--no-password never prompt for password
- -W,--password force password prompt
- --maintenance-db=dbname Alternate Maintenance Database
- By default, a database with the same name as the current user is created.
- Report bugs to <[email Protected]>.
- [Email protected] ~]$
- [Email protected] ~]$
- [Email protected] ~]$/data/pgsql/bin/createdb zwcdb
[Plain]View Plaincopyprint?
- [Email protected] ~]$ psql-u zhongwc-d zwcdb
- Psql (9.2.2)
- Type ' help ' for help.
- Zwcdb=> Help
- You is using Psql, the command-line interface to PostgreSQL.
- Type: \copyright for distribution Terms
- \h for help with SQL commands
- \? For help with Psql commands
- \g or terminate with semicolon to execute query
- \q to quit
- Zwcdb=>
Create a table
[Plain]View Plaincopyprint?
- [Email protected] data]$ psql-u zhongwc-d zwcdb-h 192.168.1.203-p 1521
- Password for user zhongwc:
- Psql (9.2.2)
- Type ' help ' for help.
- Zwcdb=> CREATE TABLE T_ZHONGWC (PID integer,pname varchar (+), constraint ZHONGWC_PID_PK primary key (PID));
- Notice:create table/primary KEY would CREATE implicit index "ZHONGWC_PID_PK" for TABLE "T_ZHONGWC"
- CREATE TABLE
- Zwcdb=>
- Zwcdb=> select * from T_ZHONGWC;
- PID | PName
- -----+-------
- (0 rows)
Delete a table
[Plain]View Plaincopyprint?
- zwcdb=> drop table T_ZHONGWC;
- DROP TABLE
- zwcdb=> drop table T_ZHONGWC;
- Error:table "T_ZHONGWC" does not exist
Postgres Create user, table