yum install postgre
sql-server postgre
sql su - postgres initdb -D /var/lib/pg
sql/data bash-4.1$ service postgre
sql start Starting postgre
sql service: /etc/init.d/postgre
sql: line 114: echo: write error: Permission denied bash-4.1$ exit exit [root@cdh2 local]# service postgre
sql start Starting postgre
sql service: [ OK ] [root@cdh2 local]# [root@cdh2 local]# su - postgres -bash-4.1$ -bash-4.1$ service postgre
sql status postmaster (pid 9745) is running... -bash-4.1$ http://www.ruanyifeng.com/blog/2013/12/getting_started_with_postgre
sql.html http://www.ruanyifeng.com/blog/2013/12/getting_started_with_postgre
sql.html http://blog.chinaunix.net/uid-26184465-id-3527130.html http://blog.chinaunix.net/uid-26184465-id-3527130.html http://blog.chinaunix.net/uid-22920230-id-3493064.html http://blog.chinaunix.net/uid-22920230-id-3493064.html cat /var/liinitdb -D /var/lib/pg
sql/data^C -bash-4.1$ service postgre
sql status postmaster (pid 9745) is running... -bash-4.1$ id uid=26(postgres) gid=26(postgres) groups=26(postgres) -bash-4.1$ vim /var/lib/pg
sql/data/postgre
sql.conf -bash-4.1$ cat /var/lib/pg
sql/data/pg_hba.conf # Postgre
sql Client Authentication Con
figuration File # =================================================== # # Refer to the "Client Authentication" section in the # Postgre
sql documentation for a complete description # of this file. A short sy
nopsis follows. # # This file controls: which hosts are allowed to connect,how clients # are authenticated,which Postgre
sql user names t
hey can use,which # databases t
hey can access. Records take one of these forms: # # local DATABASE USER METHOD [OPTIONS] # host DATABASE USER CIDR-ADDRESS METHOD [OPTIONS] # hostssl DATABASE USER CIDR-ADDRESS METHOD [OPTIONS] # hostnossl DATABASE USER CIDR-ADDRESS METHOD [OPTIONS] # # (The uppercase items must be replaced by actual values.) # # The f
irst field is the connection type: "local" is a Unix-domain socket,# "host" is either a plain or SSL-encrypted
TCP/IP socket,"hostssl" is an # SSL-encrypted
TCP/IP socket,and "hostnossl" is a plain
TCP/IP socket. # # DATABASE can be "all","sameuser","samerole",a database name,or # a comma-sep
arated list thereof. # # USER can be "all",a user name,a group name prefixed with "+",or # a comma-sep
arated list thereof. In both the DATABASE and USER fields # you can also write a file name prefixed with "@" to include names from # a sep
arate file. # # CIDR-ADDRESS specifies the set of hosts the record matches. # It is made up of an IP address and a CIDR mask that is an integer # (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that specifies # the number of significant bits in the mask. Alternatively,you can write # an IP address and netmask in sep
arate columns to specify the set of hosts. # # METHOD can be "trust","reject","md5","password","gss","
sspi","krb5",# "ident","pam","ldap" or "cert". Note that "password" sends passwords # in clear text; "md5" is preferred since it sends encrypted passwords. # # OPTIONS are a set of options for the authentication in the format # NAME=VALUE. The available options depend on the different authentication # methods - refer to the "Client Authentication" section in the documentation # for a list of which options are available for which authentication methods. # # Database and user names containing spaces,commas,quotes and other special # ch
aracters must be quoted. Quoting one of the keywords "all","sameuser" or # "samerole" makes the name lose its special ch
aracter,and just match a # database or username with that name. # # This file is read on server startup and when the postmaster receives # a SIGHUP signal. If you edit the file on a running sy
stem,you have # to SIGHUP the postmaster for the changes to take effect. You can use # "pg_ctl reload" to do that. # Put your actual con
figuration here # ---------------------------------- # # If you want to allow non-local connections,you need to add more # "host" records. In that case you will also need to make Postgre
sql listen # on a non-local interface via the listen_addresses con
figuration p
arameter,# or via the -i or -h command line switches. # # CAUTION: Con
figuring the sy
stem for local "trust" authentication allows # any local user to connect as any Postgre
sql user,including the database # superuser. If you do not trust all your local users,use another # authentication method. # TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: #host all all 127.0.0.1/32 trust host all all 0.0.0.0/0 trust # IPv6 local connections: host all all ::1/128 trust -bash-4.1$ service postgre
sql restart Stopping postgre
sql service: [
Failed] Starting postgre
sql service: /etc/init.d/postgre
sql: line 114: echo: write error: Permission denied touch: cannot touch `/var/lock/subsys/postgre
sql': Permission denied /etc/init.d/postgre
sql: line 122: /var/run/postmaster.5432.pid: Permission denied -bash-4.1$ exit
logout [root@cdh2 local]# service postgre
sql restart Stopping postgre
sql service: [ OK ] Starting postgre
sql service: [ OK ] [root@cdh2 local]# su - postgres -bash-4.1$ id uid=26(postgres) gid=26(postgres) groups=26(postgres) -bash-4.1$ p
sql -U postgres -W Password for user postgres: p
sql (8.4.20) Type "help" for help. postgres=# CREATE USER <user> WITH PASSWORD '<password>'; ERROR:
Syntax error at or near "<" LINE 1: CREATE USER <user> WITH PASSWORD '<password>'; ^ postgres=# CREATE USER postUser WITH PASSWORD 'postPwd'; CREATE ROLE postgres=# CREATE DATABASE test OWNER postUser ENCODING 'UTF8'; CREATE DATABASE postgres=# postgres=# p
sql -U kongxx -d test postgres-# p
sql -U postUser -d test postgres-# p
sql -U postUser -d test postgres-# id postgres-# p
sql --version postgres-# exit postgres-# help postgres-# "help" postgres-# p
sql -h localhost -U postgres -d test postgres-# ls/ postgres-# CREATE DATABASE test1 OWNER postgres ENCODING 'UTF8' postgres-# p
sql -U postgres -d test1 postgres-# ^Z [1]+ Stopped p
sql -U postgres -W -bash-4.1$ p
sql -U postgres -d test1 p
sql: FATAL: database "test1" does not exist -bash-4.1$ p
sql -U postUser -d test p
sql: FATAL: role "postUser" does not exist -bash-4.1$ CREATE USER postUser WITH PASSWORD 'postPwd'; -bash: CREATE: command not found -bash-4.1$ p
sql -U postgres -W Password for user postgres: p
sql (8.4.20) Type "help" for help. postgres=# CREATE DATABASE test WITH OWNER = postgres ENCODING = 'UTF8'; ERROR: database "test" already exists postgres=# CREATE DATABASE test2 WITH OWNER = postgres ENCODING = 'UTF8'; CREATE DATABASE postgres=# /p
sql -h localhost -U postgres -d test2 postgres-# p
sql -h localhost -U postgres -d test2 postgres-# \l List of databases Name | Owner | Encoding | Collation | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres : postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres : postgres=CTc/postgres test | postuser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | test2 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (5 rows) postgres-# p
sql --version postgres-# \l List of databases Name | Owner | Encoding | Collation | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres : postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres : postgres=CTc/postgres test | postuser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | test2 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (5 rows) postgres-# select * from pg_database; ERROR:
Syntax error at or near "/" LINE 1: /p
sql -h localhost -U postgres -d test2 ^ postgres=# select * from pg_database; datname | datdba | encoding | datcollate | datctype | dati
stemplate | datallowconn | datconnlimit | datlastsysoid | datfrozenxid | dattablespace | dat con
fig | datacl -----------+--------+----------+-------------+-------------+---------------+--------------+--------------+---------------+--------------+---------------+---- -------+------------------------------------- template1 | 10 | 6 | en_US.UTF-8 | en_US.UTF-8 | t | t | -1 | 11563 | 648 | 1663 | | {=c/postgres,postgres=CTc/postgres} template0 | 10 | 6 | en_US.UTF-8 | en_US.UTF-8 | t | f | -1 | 11563 | 648 | 1663 | | {=c/postgres,postgres=CTc/postgres} postgres | 10 | 6 | en_US.UTF-8 | en_US.UTF-8 | f | t | -1 | 11563 | 648 | 1663 | | test | 16384 | 6 | en_US.UTF-8 | en_US.UTF-8 | f | t | -1 | 11563 | 648 | 1663 | | test2 | 10 | 6 | en_US.UTF-8 | en_US.UTF-8 | f | t | -1 | 11563 | 648 | 1663 | | (5 rows) postgres=# select * from pg_database; datname | datdba | encoding | datcollate | datctype | dati
stemplate | datallowconn | datconnlimit | datlastsysoid | datfrozenxid | dattablespace | dat con
fig | datacl -----------+--------+----------+-------------+-------------+---------------+--------------+--------------+---------------+--------------+---------------+---- -------+------------------------------------- template1 | 10 | 6 | en_US.UTF-8 | en_US.UTF-8 | t | t | -1 | 11563 | 648 | 1663 | | {=c/postgres,postgres=CTc/postgres} postgres | 10 | 6 | en_US.UTF-8 | en_US.UTF-8 | f | t | -1 | 11563 | 648 | 1663 | | test | 16384 | 6 | en_US.UTF-8 | en_US.UTF-8 | f | t | -1 | 11563 | 648 | 1663 | | test2 | 10 | 6 | en_US.UTF-8 | en_US.UTF-8 | f | t | -1 | 11563 | 648 | 1663 | | (5 rows) postgres=# \dt No relations found. postgres=# \c test Password for user postgres: p
sql (8.4.20) You are
Now connected to database "test". test=# \dt No relations found. test=# CREATE TABLE user_tbl(name VARCHAR(20),signup_date DATE); CREATE TABLE test=# \dt List of relations Schema | Name | Type | Owner --------+----------+-------+---------- public | user_tbl | table | postgres (1 row) test=# SELECT * FROM user_tbl; name | signup_date ------+------------- (0 rows) test=# INSERT INTO user_tbl(name,signup_date) VALUES('张三','2013-12-22'); INSERT 0 1 test=# SELECT * FROM user_tbl; name | signup_date ------+------------- 张三 | 2013-12-22 (1 row) test=# commit; WARNING: there is no transaction in progress COMMIT test=# UPDATE user_tbl set name = '李四' WHERE name = '张三'; UPDATE 1 test=# SELECT * FROM user_tbl; name | signup_date ------+------------- 李四 | 2013-12-22 (1 row) test=# ALTER TABLE user_tbl ADD email VARCHAR(40); ALTER TABLE test=# desc user_tbl test-# ALTER TABLE user_tbl ALTER COLUMN signup_date SET NOT NULL; ERROR:
Syntax error at or near "desc" LINE 1: desc user_tbl ^ test=# ALTER TABLE user_tbl ALTER COLUMN signup_date SET NOT NULL; ALTER TABLE test=# ALTER TABLE user_tbl RENAME COLUMN signup_date TO signup; ALTER TABLE test=# ALTER TABLE user_tbl RENAME TO backup_tbl; ALTER TABLE test=# \dt List of relations Schema | Name | Type | Owner --------+------------+-------+---------- public | backup_tbl | table | postgres (1 row) test=# \du List of roles Role name | Attributes | Member of -----------+-------------+----------- postgres | Superuser | {} : Create role : Create DB postuser | | {} test=# \conninfo Invalid command \conninfo. Try \? for help. test=# \conninfo Invalid command \conninfo. Try \? for help. test=# \dt List of relations Schema | Name | Type | Owner --------+------------+-------+---------- public | backup_tbl | table | postgres (1 row) test=# \d backup_tbl Table "public.backup_tbl" Column | Type | Modifiers --------+-----------------------+----------- name | ch
aracter
varying(20) | signup | date | not null email | ch
aracter
varying(40) | test=# ALTER TABLE user_tbl RENAME COLUMN signup TO signup_todate; ERROR: relation "user_tbl" does not exist test=# ALTER TABLE user_tbl RENAME COLUMN signup TO signup_todate; ERROR: relation "user_tbl" does not exist test=# ALTER TABLE backup_tbl RENAME to user_tbl; ALTER TABLE test=# \d backup_tbl Did not find any relation named "backup_tbl". test=# \dt List of relations Schema | Name | Type | Owner --------+----------+-------+---------- public | user_tbl | table | postgres (1 row) test=# \d user_tbl Table "public.user_tbl" Column | Type | Modifiers --------+-----------------------+----------- name | ch
aracter
varying(20) | signup | date | not null email | ch
aracter
varying(40) | test=# ALTER TABLE user_tbl RENAME COLUMN signup TO signup_todate; ALTER TABLE test=# \d user_tbl Table "public.user_tbl" Column | Type | Modifiers ---------------+-----------------------+----------- name | ch
aracter
varying(20) | signup_todate | date | not null email | ch
aracter
varying(40) | test=# \? General \
copyright show Postgre
sql usage and
distribution terms \g [FILE] or ; execute query (and send results to file or |pipe) \h [NAME] help on
Syntax of
sql commands,* for all commands \q quit p
sql Query Buffer \e [FILE] edit the query buffer (or file) with external editor \ef [FUNCNAME] edit function de
Finition with external editor \p show the contents of the query buffer \r reset (clear) the query buffer \s [FILE]
display history or save it to file \w FILE write query buffer to file Input/Output \
copy ... perform
sql copY with data stream to the client host \echo [STRING] write string to standard output \i FILE execute commands from file \o [FILE] send all query results to file or |pipe \qecho [STRING] write string to query output stream (see \o) @R_740_
4045@ional (options: S = show sy
stem objects,+ = additional detail) \d[S+] list tables,views,and sequences \d[S+] NAME describe table,view,sequence,or index \da[+] [PATTERN] list aggregates \db[+] [PATTERN] list tablespaces \dc[S] [PATTERN] list conversions \dC [PATTERN] list casts \dd[S] [PATTERN] show comments on objects \dD[S] [PATTERN] list domains \des[+] [PATTERN] list foreign servers \deu[+] [PATTERN] list user mappings \dew[+] [PATTERN] list foreign-data wrappers \df[antw][S+] [PATRN] list [only agg/
normal/trigger/window] functions \dF[+] [PATTERN] list text search con
figurations \dFd[+] [PATTERN] list text search dictionaries \dFp[+] [PATTERN] list text search parsers --More-- test=# SELECT version(); version ----------------------------------------------------------------------------------------------------------------- Postgre
sql 8.4.20 on i386-redhat-linux-gnu,compiled by GCC gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17),32-bit (1 row) test=#
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。