Postgresql日常運維-安裝(Linux)01

chenoracle發表於2020-04-02

Postgresql 12.2 日常運維 - 安裝 (Linux)01

一:Linux 下安裝 Postgresql

二:Windows 下安裝 Postgresql

一:Linux 下安裝 Postgresql

環境說明:

Linux OS:Red Hat Enterprise Linux Server release 7.5 (Maipo)

Windows OS:Windows 10

DB PostgreSQL 12.2

1 下載 PostgreSQL 12.2

https://www.postgresql.org/

二進位制包下載

原始碼包下載

本次實驗使用原始碼包

......

[root@cjcos package]# pwd

/package

[root@cjcos package]# ll -rth postgresql-12.2.tar.gz

-rw-r--r-- 1 root root 26M Apr  2 11:11 postgresql-12.2.tar.gz

[root@cjcos package]# md5sum postgresql-12.2.tar.gz

939acc9359abf0de9838965947a19158  postgresql-12.2.tar.gz

2 建立使用者,組,目錄等

[root@cjcos ~]# groupadd postgres

[root@cjcos ~]# useradd -g postgres postgres

[root@cjcos ~]# passwd postgres

[root@cjcos ~]# mkdir /usr/local/pgsql/data -p

[root@cjcos ~]# chown postgres.postgres /usr/local/pgsql -R

[root@cjcos package]# chown postgres.postgres /package/postgres -R

3 解壓

[root@cjcos package]# su - postgres

[postgres@cjcos ~]$ cd /package/postgres/

[postgres@cjcos postgres]$ ll -rth

total 26M

-rw-r--r-- 1 postgres postgres 26M Apr  2 11:11 postgresql-12.2.tar.gz

[postgres@cjcos postgres]$ tar -zxvf postgresql-12.2.tar.gz

4 安裝

[postgres@cjcos postgres]$ cd postgresql-12.2/

[postgres@cjcos postgresql-12.2]$ pwd

/package/postgres/postgresql-12.2

[postgres@cjcos postgresql-12.2]$ ./configure --prefix=/usr/local/pgsql

[postgres@cjcos postgresql-12.2]$ make

......

All of PostgreSQL successfully made. Ready to install.

[postgres@cjcos postgresql-12.2]$ make  install

......

PostgreSQL installation complete.

[root@cjcos pgsql]# pwd

/usr/local/pgsql

[root@cjcos pgsql]# ls

bin  data  include  lib  share

5 配置環境變數

[postgres@cjcos ~]$ vim .bash_profile

export PGHOME=/usr/local/pgsql

export PGDATA=/usr/local/pgsql/data

PATH=$PATH:$HOME/bin:$PGHOME/bin

[postgres@cjcos ~]$ source .bash_profile

6 使用initdb 初使用化資料庫

[postgres@cjcos bin]$ ./initdb -D /usr/local/pgsql/data

[root@cjcos data]# pwd

/usr/local/pgsql/data

[root@cjcos data]# ls

base     pg_hba.conf    pg_notify     pg_stat_tmp  pg_twophase  postgresql.conf

global   pg_ident.conf  pg_serial     pg_subtrans  PG_VERSION

pg_clog  pg_multixact   pg_snapshots  pg_tblspc    pg_xlog

7 修改引數

[root@cjcos data]# vim postgresql.conf

#listen_addresses = 'localhost'         # what IP address(es) to listen on;

                                        # comma-separated list of addresses;

                                        # defaults to 'localhost'; use '*' for all

                                        # (change requires restart)

#port = 5432                            # (change requires restart)

listen_addresses = '*'

[root@cjcos data]# vim pg_hba.conf

# IPv4 local connections:

host    all             all             0.0.0.0/0               trust

host    all             all             127.0.0.1/32            trust

8 啟動資料庫

[postgres@cjcos bin]$ ./pg_ctl -D /usr/local/pgsql/data -l logfile start

waiting for server to start.... done

server started

9 登入資料庫

[postgres@cjcos bin]$ ./psql

psql (12.2)

Type "help" for help.

postgres=# select current_setting('server_version_num');

 current_setting

-----------------

 120002

(1 row)

10 問題彙總:

問題一: configure: error: readline library not found

問題原因:沒有安裝 readline-devel

解決方案:通過yum 安裝 readline-devel

過程如下:

[postgres@cjcos postgresql-12.2]$ ./configure --prefix=/usr/local/pgsql

......

checking for library containing readline... no

configure: error: readline library not found

If you have readline already installed, see config.log for details on the

failure.  It is possible the compiler isn't looking in the proper directory.

Use --without-readline to disable readline support.

[root@cjcos pgsql]# rpm -qa | grep readline

readline-6.2-10.el7.x86_64

[root@cjcos pgsql]# yum search readline

掛載映象

[root@cjcos yum.repos.d]# mount /package/V975367-01.iso /mnt -o loop

配置本地yum

[root@cjcos yum.repos.d]# cat yum.repo

[Oralin7u5]

name=local yum

baseurl=file:///mnt

gpgcheck=0

enabled=1

安裝

[root@cjcos pgsql]# yum -y install -y readline-devel

同時安裝其他依賴包

[root@cjcos yum.repos.d]# yum -y install perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake

問題二:postgresql 啟動報錯版本不相容

問題原因:在安裝postgresql12.2 之前,作業系統上已經預設安裝了一個 9.2 版本的 pg

解決方案:解除安裝pg9.2 ,重新初始化資料庫。

過程如下:

[postgres@cjcos bin]$ ./pg_ctl -D /usr/local/pgsql/data -l logfile start

......

2020-04-02 14:43:25.405 CST [27701] FATAL:  database files are incompatible with server

2020-04-02 14:43:25.405 CST [27701] DETAIL:   The data directory was initialized by PostgreSQL version 9.2, which is not compatible with this version 12.2.

 stopped waiting

pg_ctl: could not start server

Examine the log output.

[root@cjcos ~]# rpm -qa|grep postgre

postgresql-docs-9.2.23-3.el7_4.x86_64

postgresql-9.2.23-3.el7_4.x86_64

postgresql-libs-9.2.23-3.el7_4.x86_64

postgresql-server-9.2.23-3.el7_4.x86_64

[root@cjcos ~]# rpm -e postgresql-docs-9.2.23-3.el7_4.x86_64

[root@cjcos ~]# rpm -e postgresql-9.2.23-3.el7_4.x86_64 --nodeps

[root@cjcos ~]# rpm -e postgresql-libs-9.2.23-3.el7_4.x86_64 --nodeps

[root@cjcos ~]# rpm -e postgresql-server-9.2.23-3.el7_4.x86_64

[postgres@cjcos bin]$ ./initdb -D /usr/local/pgsql/data

[postgres@cjcos bin]$ ./pg_ctl -D /usr/local/pgsql/data -l logfile start

歡迎關注我的微信公眾號"IT小Chen",共同學習,共同成長!!!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29785807/viewspace-2684244/,如需轉載,請註明出處,否則將追究法律責任。

相關文章