加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql 安装

发布时间:2020-12-13 18:20:00 所属栏目:百科 来源:网络整理
导读:版本: [yuming@com4 ~]$ lsb_release -aLSB Version: :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarchDistributor ID: RedHatEnterpriseServerDescription: Red Hat Enterprise Linux Ser


版本:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读