微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

postgresql 安装


版本:

[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=# 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐