postgresql編譯安裝及配置

來源:互聯網
上載者:User

標籤:sql   postgre   編譯安裝   


1、建立postgres使用者

[[email protected] source]# adduser postgres


2、下載postgresql源碼

[[email protected] source]# pwd

/home/postgres/source

[[email protected] source]# wget https://ftp.postgresql.org/pub/source/v9.6.1/postgresql-9.6.1.tar.gz


3、編譯安裝postgresql:

[[email protected] source]# pwd

/home/postgres/source

[[email protected] source]# tar zxf postgresql-9.6.1.tar.gz

[[email protected] source]# cd postgresql-9.6.1

[[email protected] postgresql-9.6.1]# ./configure --prefix=/usr/local/pgsql9.6.1 

[[email protected] postgresql-9.6.1]# gmake -j 8

[[email protected] postgresql-9.6.1]# gmake install


4.初始化資料庫:

mkdir -p /data/postgresql5.6/data

chown -R postgres.postgres /data/postgresql5.6/data

[[email protected] postgresql-9.6.1]# su - postgres

[[email protected] data]$ 

 /usr/local/pgsql9.6/bin/initdb --no-locale  -D /data/postgresql5.6/data -E utf8 -U postgres -W


[[email protected] data]$  /usr/local/pgsql9.6/bin/initdb --no-locale  -D /data/postgresql5.6/data -E utf8 -U postgres -W

The files belonging to this database system will be owned by user "postgres".

This user must also own the server process.

The database cluster will be initialized with locale "C".

The default text search configuration will be set to "english".

Data page checksums are disabled.

Enter new superuser password: (要求輸入超級使用者postgres密碼)

Enter it again: 

fixing permissions on existing directory /data/postgresql5.6/data ... ok

creating subdirectories ... ok

selecting default max_connections ... 100

selecting default shared_buffers ... 128MB

selecting dynamic shared memory implementation ... posix

creating configuration files ... ok

running bootstrap script ... ok

performing post-bootstrap initialization ... ok

syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections

You can change this by editing pg_hba.conf or using the option -A, or

--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:


 /usr/local/pgsql9.6/bin/pg_ctl -D /data/postgresql5.6/data -l logfile start


/usr/local/pgsql9.6/bin/initdb --no-locale  -D /data/postgresql5.6/data -E utf8 -U postgres -W

5.初始化資料庫的參數介紹:

 initdb [OPTION] [DATADIR]


選項:

    -A,--auth=METHOD:指定本地串連的認證方法

    [-D,--pgdata=]DATADIR:指定資料庫簇的原始目錄(必須為空白)

    -E,--encoding=ENCODING:指定資料庫的預設編碼

    --locale=LOCALE:設定資料庫的locale

    --no-locale:等價--locale=C

    --pwfile=FILE:從指定的檔案FILE中讀取超級使用者的密碼

    -T,--text-search-config=CFG:指定預設的配置

    -U,--username=Username:指定使用者名稱

    -W,--pwprompt:強制提示密碼輸入

    -X,--xlogdir=XLOGDIR:指定交易記錄的目錄檔案


[[email protected] data]$ ls

base    pg_clog       pg_dynshmem  pg_ident.conf  pg_multixact  pg_replslot  pg_snapshots  pg_stat_tmp  pg_tblspc    PG_VERSION  postgresql.auto.conf

global  pg_commit_ts  pg_hba.conf  pg_logical     pg_notify     pg_serial    pg_stat       pg_subtrans  pg_twophase  pg_xlog     postgresql.conf


6、配置postgresql.conf

允許服務監聽範圍,0.0.0.0允許監聽所有 IPv4 地址

listen_addresses = ‘0.0.0.0‘

port = 10637 

#使用者訪問日誌格式 

log_destination = ‘csvlog‘

#啟用使用者訪問記錄收集器

logging_collector = on

##指定作業記錄存放路徑,指定作業記錄檔案名稱

log_directory = ‘/data/postgresql5.6/log‘   

log_filename = ‘postgresql-%Y-%m-%d_%H%M%S.log‘


7、配置pg_hba.conf

#只給本地和192.168.0.0串連

host    all             all             127.0.0.1/32           md5

host    all             all             192.168.0.0/24         md5


8、配置Postgresql環境變數

在/etc/profile檔案中增加下面內容

PGDATA=/data/postgresql5.6/data

PGHOST=127.0.0.1

PGDATABASE=postgres

PGUSER=postgres

PGPORT=10637

##PGPASSWORD="123456"

PATH=/usr/local/pgsql/bin:$PATH

export PGDATA PGHOST PGDATABASE PGUSER PGPORT PATH PGPASSWORD

環境變數生效

[[email protected] postgresql-9.6]# source /etc/profile

[[email protected] postgresql-9.6]# which psql

/usr/local/pgsql9.6/bin/psql


9.下面配置postgresql的動態庫到搜尋路徑中

[[email protected] postgresql-9.6]# vim /etc/ld.so.conf.d/pgsql.conf 

/usr/local/pgsql/lib

搜尋路徑生效

[[email protected] postgresql-9.6]# ldconfig 

[[email protected] jumpserver]#  ldconfig -p  | grep libpq

libpqwalreceiver.so (libc6,x86-64) => /usr/local/pgsql9.6/lib/libpqwalreceiver.so

libpq.so.5 (libc6,x86-64) => /usr/local/pgsql9.6/lib/libpq.so.5

libpq.so (libc6,x86-64) => /usr/local/pgsql9.6/lib/libpq.so


10、啟動PostgreSQL服務

因為我們上面配置了環境變數,所以我們可以這樣啟動服務

[[email protected] postgresql-9.6.1]# su - postgres

[[email protected] postgresql-9.6]$ pg_ctl start

 該命令與下面的語句是一樣的效果

[[email protected] postgresql-9.6 ]$ /usr/local/pgsql9.6/bin/pg_ctl -D /data/postgresql5.6/data  start


本文出自 “10931853” 部落格,謝絕轉載!

postgresql編譯安裝及配置

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.