版本:
[yuming@com4 ~]$ lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: RedHatEnterpriseServer
Description: Red Hat Enterprise Linux Server release 6.2 (Santiago)
Release: 6.2
Codename: Santiago
[root@com4 ~]# ll | grep postgres
-rwxr-xr-x. 1 root root 50157920 Nov 19 02:14 postgresql-9.1.1-1-linux-x64.bin
使用bin包安裝
[root@com4 ~]# ./postgresql-9.1.1-1-linux-x64.bin
----------------------------------------------------------------------------
Welcome to the PostgreSQL Setup Wizard.
----------------------------------------------------------------------------
Please specify the directory where PostgreSQL will be installed.
Installation Directory [/opt/PostgreSQL/9.1]:
----------------------------------------------------------------------------
Please select a directory under which to store your data.
Data Directory [/opt/PostgreSQL/9.1/data]:
----------------------------------------------------------------------------
Please provide a password for the database superuser (postgres). A locked Unix
user account (postgres) will be created if not present.
Password :
Retype password :
----------------------------------------------------------------------------
Please select the port number the server should listen on.
Port [5432]:
----------------------------------------------------------------------------
Advanced Options
Select the locale to be used by the new database cluster.
Locale
[1] [Default locale]
[2] aa_DJ
...................
[712] zu_ZA
[713] zu_ZA.iso88591
[713] zu_ZA.iso88591
[714] zu_ZA.utf8
Please choose an option [1] :
----------------------------------------------------------------------------
Setup is now ready to begin installing PostgreSQL on your computer.
Do you want to continue? [Y/n]: Y
----------------------------------------------------------------------------
Please wait while Setup installs PostgreSQL on your computer.
Installing
0% ______________ 50% ______________ 100%
#########################################
----------------------------------------------------------------------------
Setup has finished installing PostgreSQL on your computer.
安裝後,服務已啓動,查看裝到了哪兒:
[root@com4 network-scripts]# ps -ef | grep postgres
postgres 1708 1 0 04:22 ? 00:00:00 /opt/PostgreSQL/9.1/bin/postgres -D /opt/PostgreSQL/9.1/data
postgres 1709 1708 0 04:22 ? 00:00:00 postgres: logger process
postgres 1711 1708 0 04:22 ? 00:00:00 postgres: writer process
postgres 1712 1708 0 04:22 ? 00:00:00 postgres: wal writer process
postgres 1713 1708 0 04:22 ? 00:00:00 postgres: autovacuum launcher process
postgres 1714 1708 0 04:22 ? 00:00:00 postgres: stats collector process
root 3400 2547 0 04:31 pts/0 00:00:00 grep postgres
找到psql文件,登錄,若嫌麻煩可將安裝目錄加入Path:
[root@com4 network-scripts]# psql
bash: psql: command not found
[root@com4 network-scripts]# su postgres
bash-4.1$ psql
bash: psql: command not found
bash-4.1$ /opt/PostgreSQL/9.1/bin/psql
Password:
psql.bin (9.1.1)
Type "help" for help.
postgres=# \d
No relations found.
postgres=# \t
Showing only tuples.
postgres=# \l
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
postgres=# \c postgres
You are now connected to database "postgres" as user "postgres".
postgres=# \d
No relations found.
允許遠程連接:
修改 pg_hba.conf 文件,在 “host all all 127.0.0.1/32 md5”下面添加一行:
host all all 192.168.1.106/24 md5
修改 postgresql.conf 文件,在 #standard_conforming_strings = on 下添加一行:
standard_conforming_strings = off
有的版本還需要檢查 postgresql.conf 文件中監聽地址是否能監聽客戶端:
listen_addresses = '*' # what IP address(es) to listen on;
重啓:
[root@com4 Desktop]# /etc/init.d/postgresql-9.1 status
pg_ctl: server is running (PID: 1708)
/opt/PostgreSQL/9.1/bin/postgres "-D" "/opt/PostgreSQL/9.1/data"
[root@com4 data]# /etc/init.d/postgresql-9.1 restart
關閉開機自動啓動:
[yuming@com4 Desktop]$ runlevel
N 5
[root@com4 Desktop]# chkconfig --level 5 postgresql-9.1 off
關閉防火牆,進行遠程連接:
[root@indigo apache]# psql -h 192.168.1.109 -p 5432 -U postgres -W pg -d postgres
psql: warning: extra command-line argument "pg" ignored
Password for user postgres:
psql (9.2.4, server 9.1.1)
WARNING: psql version 9.2, server version 9.1.
Some psql features might not work.
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | 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
(3 rows)
postgres=#