【云圖說】第132期 小云妹帶您快速玩轉RDS實例操作(2)——刪除與退訂
874
2025-04-02
在Oracle Linux 7.1中使用源碼來安裝postgresql 9.6
編譯postgresql需要下列軟件包:
1.GUN make版本3.80或新的要求。
[root@cs1 /]# make --version
GNU Make 3.82
Built for x86_64-redhat-linux-gnu
Copyright ? 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
3.除了gzip和bzip2之外,我們還需要tar來解包源代碼發布。
4.GNU Readline庫
[root@cs1 /]# rpm -aq | grep readline
readline-6.2-9.el7.x86_64
[root@cs1 /]# rpm -aq | grep readline-deve
readline-devel-6.2-9.el7.x86_64
[root@cs1 /]# rpm -aq | grep libedit
libedit-3.0-12.20121213cvs.el7.x86_64
5.可選工具包在默認配置的時候并不要求它們,但是如果打開了一些編譯選項之后就需要它們了
perl 5.8 or later
python
Kerberos
OpenSSL
OpenLDAP and/or PAM
Flex 2.5.31 or later
Bison 1.875 or later
6.創建用戶與組
[root@cs1 local]# groupadd pgsql
[root@cs1 local]# useradd -g pgsql pgsql
7.下載源碼包postgresql-9.6.6.tar.gz并上傳到服務器并解壓
[root@cs1 local]# gunzip
[root@cs1 local]# ls -lrt
總用量 8
drwxr-xr-x. 2 root root 6 5月 8 2014 src
drwxr-xr-x. 2 root root 6 5月 8 2014 sbin
drwxr-xr-x. 2 root root 6 5月 8 2014 libexec
drwxr-xr-x. 2 root root 6 5月 8 2014 lib64
drwxr-xr-x. 2 root root 6 5月 8 2014 lib
drwxr-xr-x. 2 root root 6 5月 8 2014 include
drwxr-xr-x. 2 root root 6 5月 8 2014 games
drwxr-xr-x. 2 root root 6 5月 8 2014 etc
drwxr-xr-x. 5 root root 46 10月 12 2017 share
drwxrwxrwx 6 pgsql pgsql 4096 11月 7 2017 postgresql-9.6.6
drwxr-xr-x. 2 root root 46 3月 9 2018 bin
drwxrwxr-x 13 root mysql 4096 1月 31 02:40 mariadb-10.0.38-linux-glibc_214-x86_64
lrwxrwxrwx 1 root root 38 6月 4 14:43 mysql -> mariadb-10.0.38-linux-glibc_214-x86_64
創建一個軟鏈接
[root@cs1 local]# ln -s postgresql-9.6.6 pgsql
[root@cs1 local]# ls -lrt
總用量 8
drwxr-xr-x. 2 root root 6 5月 8 2014 src
drwxr-xr-x. 2 root root 6 5月 8 2014 sbin
drwxr-xr-x. 2 root root 6 5月 8 2014 libexec
drwxr-xr-x. 2 root root 6 5月 8 2014 lib64
drwxr-xr-x. 2 root root 6 5月 8 2014 lib
drwxr-xr-x. 2 root root 6 5月 8 2014 include
drwxr-xr-x. 2 root root 6 5月 8 2014 games
drwxr-xr-x. 2 root root 6 5月 8 2014 etc
drwxr-xr-x. 5 root root 46 10月 12 2017 share
drwxrwxrwx 6 pgsql pgsql 4096 11月 7 2017 postgresql-9.6.6
drwxr-xr-x. 2 root root 46 3月 9 2018 bin
drwxrwxr-x 13 root mysql 4096 1月 31 02:40 mariadb-10.0.38-linux-glibc_214-x86_64
lrwxrwxrwx 1 root root 38 6月 4 14:43 mysql -> mariadb-10.0.38-linux-glibc_214-x86_64
lrwxrwxrwx 1 root root 16 6月 4 21:24 pgsql -> postgresql-9.6.6
8.安裝
root@cs1 local]# cd pgsql
8.1安裝過程的第一步就是為你的系統配置源代碼樹并選擇你喜歡的選項。這個工作是通過運行configure腳本實現的,對于默認安裝,你只需要簡單地輸入:
[root@cs1 pgsql]# ./configure
checking build system type… x86_64-pc-linux-gnu
…省略…
configure: using CPPFLAGS= -D_GNU_SOURCE
configure: using LDFLAGS= -Wl,–as-needed
configure: creating ./config.status
config.status: creating GNUmakefile
config.status: creating src/Makefile.global
config.status: creating src/include/pg_config.h
config.status: creating src/include/pg_config_ext.h
config.status: creating src/interfaces/ecpg/include/ecpg_config.h
config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s
config.status: linking src/backend/port/dynloader/linux.c to src/backend/port/dynloader.c
config.status: linking src/backend/port/sysv_sema.c to src/backend/port/pg_sema.c
config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
config.status: linking src/backend/port/dynloader/linux.h to src/include/dynloader.h
config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port
默認安裝目錄/usr/local/pgsql,可以使用–prefix=path進行修改,./configure --help
8.2 編譯
要開始編譯,鍵入:
root@cs1 local]# make
(一定要記得用GNU make)。依你的硬件而異,編譯過程可能需要 5 分鐘到半小時。顯示的最后一行應該是:
All of PostgreSQL successfully made. Ready to install.
如果你希望編譯所有能編譯的東西,包括文檔(HTML和手冊頁)以及附加模塊(contrib),這樣鍵入:
[root@cs1 pgsql]# make world
…省略…
make[2]: 離開目錄“/usr/local/postgresql-9.6.6/contrib/vacuumlo”
make[1]: 離開目錄“/usr/local/postgresql-9.6.6/contrib”
PostgreSQL, contrib, and documentation successfully made. Ready to install.
8.3安裝文件
要安裝PostgreSQL,輸入:
make install
這條命令將把文件安裝到在步驟 1中指定的目錄。確保你有足夠的權限向該區域寫入。通常你需要用 root 權限做這一步。或者你也可以事先創建目標目錄并且分派合適的權限。
要安裝文檔(HTML和手冊頁),輸入:
make install-docs
如果你按照上面的方法編譯了所有東西,輸入:
make install-world
這也會安裝文檔。
[root@cs1 pgsql]# make install-world
…省略…
make[2]: 離開目錄“/usr/local/postgresql-9.6.6/contrib/vacuumlo”
make[1]: 離開目錄“/usr/local/postgresql-9.6.6/contrib”
PostgreSQL, contrib, and documentation installation complete.
9.設置環境變量
創建目錄/usr/local/pgsql/data用來存放數據
[root@cs1 pgsql]# mkdir /usr/local/pgsql/data
[root@cs1 pgsql]# chown pgsql:pgsql data
[root@cs1 pgsql]# su - pgsql
[pgsql@cs1 ~]$ vi .bash_profile
.bash_profile
Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
User specific environment and startup programs
PATH=
P
A
T
H
:
PATH:
PATH:HOME/.local/bin:$HOME/bin
export PATH
export LD_LIBRARY_PATH=/usr/local/pgsql/lib
export PG_HOME=/usr/local/pgsql
export PATH=
P
G
H
O
M
E
/
b
i
n
/
:
PG_HOME/bin/:
PGH OME/bin/:PATH
export PGDATA=/usr/local/pgsql/data
10.初始化數據庫
使用pgsql用戶來執行
[pgsql@cs1 ~]$ initdb --help
initdb initializes a PostgreSQL database cluster.
Usage:
initdb [OPTION]… [DATADIR]
Options:
-A, --auth=METHOD default authentication method for local connections
–auth-host=METHOD default authentication method for local TCP/IP connections
–auth-local=METHOD default authentication method for local-socket connections
[-D, --pgdata=]DATADIR location for this database cluster
-E, --encoding=ENCODING set default encoding for new databases
–locale=LOCALE set default locale for new databases
–lc-collate=, --lc-ctype=, --lc-messages=LOCALE
–lc-monetary=, --lc-numeric=, --lc-time=LOCALE
set default locale in the respective category for
new databases (default taken from environment)
–no-locale equivalent to --locale=C
–pwfile=FILE read password for the new superuser from file
-T, --text-search-config=CFG
default text search configuration
-U, --username=NAME database superuser name
-W, --pwprompt prompt for a password for the new superuser
-X, --xlogdir=XLOGDIR location for the transaction log directory
Less commonly used options:
-d, --debug generate lots of debugging output
-k, --data-checksums use data page checksums
-L DIRECTORY where to find the input files
-n, --noclean do not clean up after errors
-N, --nosync do not wait for changes to be written safely to disk
-s, --show show internal settings
-S, --sync-only only sync data directory
Other options:
-V, --version output version information, then exit
-?, --help show this help, then exit
If the data directory is not specified, the environment variable PGDATA
is used.
Report bugs to pgsql-bugs@postgresql.org.
[pgsql@cs1 ~]$ initdb -D /usr/local/pgsql/data
The files belonging to this database system will be owned by user “pgsql”.
This user must also own the server process.
The database cluster will be initialized with locale “zh_CN.gb2312”.
The default database encoding has accordingly been set to “EUC_CN”.
initdb: could not find suitable text search configuration for locale “zh_CN.gb2312”
The default text search configuration will be set to “simple”.
Data page checksums are disabled.
fixing permissions on existing directory /usr/local/pgsql/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:
pg_ctl -D /usr/local/pgsql/data -l logfile start
同時在pgsql的目錄可以看到生成的數據目錄data以及該目錄的相關數據和配置文件:
[root@cs1 soft]# cd /usr/local/pgsql
[root@cs1 pgsql]# ls -lrt
總用量 1080
-rw-r–r-- 1 pgsql pgsql 1212 11月 7 2017 README
-rw-r–r-- 1 pgsql pgsql 1529 11月 7 2017 Makefile
-rw-r–r-- 1 pgsql pgsql 284 11月 7 2017 HISTORY
-rw-r–r-- 1 pgsql pgsql 3638 11月 7 2017 GNUmakefile.in
-rw-r–r-- 1 pgsql pgsql 1192 11月 7 2017 COPYRIGHT
-rw-r–r-- 1 pgsql pgsql 74867 11月 7 2017 configure.in
-rwxr-xr-x 1 pgsql pgsql 471555 11月 7 2017 configure
-rw-r–r-- 1 pgsql pgsql 384 11月 7 2017 aclocal.m4
drwxrwxrwx 55 pgsql pgsql 4096 11月 7 2017 contrib
drwxrwxrwx 2 pgsql pgsql 4096 11月 7 2017 config
drwxrwxrwx 3 pgsql pgsql 101 11月 7 2017 doc
-rw-r–r-- 1 pgsql pgsql 76016 11月 7 2017 INSTALL
-rwxr-xr-x 1 root root 39264 6月 4 21:29 config.status
-rw-r–r-- 1 root root 3638 6月 4 21:29 GNUmakefile
drwxrwxrwx 16 pgsql pgsql 4096 6月 4 21:29 src
-rw-r–r-- 1 root root 370213 6月 4 21:29 config.log
drwxr-xr-x 4 root root 26 6月 4 21:43 tmp_install
drwxr-xr-x 6 root root 4096 6月 4 21:45 include
drwxr-xr-x 8 root root 4096 6月 4 21:45 share
drwxr-xr-x 4 root root 4096 6月 4 21:45 lib
drwxr-xr-x 2 root root 4096 6月 4 21:45 bin
drwx------ 19 pgsql pgsql 4096 6月 4 21:56 data
[root@cs1 pgsql]# cd data
[root@cs1 data]# ls -lrt
總用量 48
drwx------ 2 pgsql pgsql 6 6月 4 21:56 pg_twophase
drwx------ 2 pgsql pgsql 6 6月 4 21:56 pg_snapshots
drwx------ 2 pgsql pgsql 6 6月 4 21:56 pg_serial
drwx------ 2 pgsql pgsql 6 6月 4 21:56 pg_replslot
drwx------ 4 pgsql pgsql 34 6月 4 21:56 pg_multixact
drwx------ 2 pgsql pgsql 6 6月 4 21:56 pg_dynshmem
drwx------ 2 pgsql pgsql 6 6月 4 21:56 pg_commit_ts
-rw------- 1 pgsql pgsql 4 6月 4 21:56 PG_VERSION
drwx------ 2 pgsql pgsql 6 6月 4 21:56 pg_tblspc
drwx------ 2 pgsql pgsql 6 6月 4 21:56 pg_stat_tmp
drwx------ 2 pgsql pgsql 6 6月 4 21:56 pg_stat
drwx------ 4 pgsql pgsql 37 6月 4 21:56 pg_logical
-rw------- 1 pgsql pgsql 22304 6月 4 21:56 postgresql.conf
-rw------- 1 pgsql pgsql 88 6月 4 21:56 postgresql.auto.conf
-rw------- 1 pgsql pgsql 1636 6月 4 21:56 pg_ident.conf
-rw------- 1 pgsql pgsql 4459 6月 4 21:56 pg_hba.conf
drwx------ 3 pgsql pgsql 58 6月 4 21:56 pg_xlog
drwx------ 2 pgsql pgsql 17 6月 4 21:56 pg_subtrans
drwx------ 2 pgsql pgsql 17 6月 4 21:56 pg_clog
drwx------ 2 pgsql pgsql 17 6月 4 21:56 pg_notify
drwx------ 2 pgsql pgsql 4096 6月 4 21:56 global
drwx------ 5 pgsql pgsql 38 6月 4 21:56 base
11.啟動數據庫
在初始化數據庫結束后看到了啟動命令:
Success. You can now start the database server using:
pg_ctl -D /usr/local/pgsql/data -l logfile start
[pgsql@cs1 ~]$ echo $PGDATA
/usr/local/pgsql/data
由于我們設置了環境變量,所以已經指定了數據目錄PGDATA, -l表示日志文件目錄,通常需要指定,所以我們在
/usr/local/pgsql根目錄下再創建一個log目錄用來存放日志文件(注意別忘記賦予可寫的權限)
[root@cs1 pgsql]# chown -R pgsql:pgsql log
[root@cs1 pgsql]# chmod -R 775 log
[root@cs1 pgsql]# ls -lrt
總用量 1080
-rw-r–r-- 1 pgsql pgsql 1212 11月 7 2017 README
-rw-r–r-- 1 pgsql pgsql 1529 11月 7 2017 Makefile
-rw-r–r-- 1 pgsql pgsql 284 11月 7 2017 HISTORY
-rw-r–r-- 1 pgsql pgsql 3638 11月 7 2017 GNUmakefile.in
-rw-r–r-- 1 pgsql pgsql 1192 11月 7 2017 COPYRIGHT
-rw-r–r-- 1 pgsql pgsql 74867 11月 7 2017 configure.in
-rwxr-xr-x 1 pgsql pgsql 471555 11月 7 2017 configure
-rw-r–r-- 1 pgsql pgsql 384 11月 7 2017 aclocal.m4
drwxrwxrwx 55 pgsql pgsql 4096 11月 7 2017 contrib
drwxrwxrwx 2 pgsql pgsql 4096 11月 7 2017 config
drwxrwxrwx 3 pgsql pgsql 101 11月 7 2017 doc
-rw-r–r-- 1 pgsql pgsql 76016 11月 7 2017 INSTALL
-rwxr-xr-x 1 root root 39264 6月 4 21:29 config.status
-rw-r–r-- 1 root root 3638 6月 4 21:29 GNUmakefile
drwxrwxrwx 16 pgsql pgsql 4096 6月 4 21:29 src
-rw-r–r-- 1 root root 370213 6月 4 21:29 config.log
drwxr-xr-x 4 root root 26 6月 4 21:43 tmp_install
drwxr-xr-x 6 root root 4096 6月 4 21:45 include
drwxr-xr-x 8 root root 4096 6月 4 21:45 share
drwxr-xr-x 4 root root 4096 6月 4 21:45 lib
drwxr-xr-x 2 root root 4096 6月 4 21:45 bin
drwx------ 19 pgsql pgsql 4096 6月 4 21:56 data
drwxrwxr-x 2 pgsql pgsql 6 6月 4 22:04 log
運行pg_ctl start -l /usr/local/pgsql/log/pg_server.log即可啟動數據庫
[pgsql@cs1 ~]$ pg_ctl start -l /usr/local/pgsql/log/pg_server.log
server starting
通過ps -ef|grep postgres查看一下postgres相關是否存在相關進程
[root@cs1 log]# ps -ef|grep postgres
pgsql 4977 1 0 22:05 pts/3 00:00:00 /usr/local/postgresql-9.6.6/bin/postgres
pgsql 4980 4977 0 22:05 ? 00:00:00 postgres: checkpointer process
pgsql 4981 4977 0 22:05 ? 00:00:00 postgres: writer process
pgsql 4982 4977 0 22:05 ? 00:00:00 postgres: wal writer process
pgsql 4983 4977 0 22:05 ? 00:00:00 postgres: autovacuum launcher process
pgsql 4984 4977 0 22:05 ? 00:00:00 postgres: stats collector process
root 5145 15622 0 22:06 pts/4 00:00:00 grep --color=auto postgres
12.連接數據庫
[pgsql@cs1 ~]$ psql --list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------±------±---------±-------------±-------------±------------------
postgres | pgsql | EUC_CN | zh_CN.gb2312 | zh_CN.gb2312 |
template0 | pgsql | EUC_CN | zh_CN.gb2312 | zh_CN.gb2312 | =c/pgsql +
| | | | | pgsql=CTc/pgsql
template1 | pgsql | EUC_CN | zh_CN.gb2312 | zh_CN.gb2312 | =c/pgsql +
| | | | | pgsql=CTc/pgsql
(3 rows)
啟動成功后我們就可以通過postgresql自帶的客戶端工具psql來進行連接,直接輸入psql看到版本信息則說明連接成功:
[pgsql@cs1 ~]$ psql postgres
psql (9.6.6)
Type “help” for help.
postgres=#
接下來要做的第一件事就是設置postgres用戶的密碼(默認為空),用psql連接成功后直接輸入\password即會提示輸入兩次密碼
[pgsql@cs1 ~]$ psql postgres
psql (9.6.6)
Type “help” for help.
postgres=# \password
Enter new password:
Enter it again:
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------±------±---------±-------------±-------------±------------------
postgres | pgsql | EUC_CN | zh_CN.gb2312 | zh_CN.gb2312 |
template0 | pgsql | EUC_CN | zh_CN.gb2312 | zh_CN.gb2312 | =c/pgsql +
| | | | | pgsql=CTc/pgsql
template1 | pgsql | EUC_CN | zh_CN.gb2312 | zh_CN.gb2312 | =c/pgsql +
| | | | | pgsql=CTc/pgsql
(3 rows)
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------±------±---------±-------------±-------------±------------------
postgres | pgsql | EUC_CN | zh_CN.gb2312 | zh_CN.gb2312 |
template0 | pgsql | EUC_CN | zh_CN.gb2312 | zh_CN.gb2312 | =c/pgsql +
| | | | | pgsql=CTc/pgsql
template1 | pgsql | EUC_CN | zh_CN.gb2312 | zh_CN.gb2312 | =c/pgsql +
| | | | | pgsql=CTc/pgsql
(3 rows)
postgres=# select version();
version
PostgreSQL 9.6.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit
(1 row)
postgres=# select current_date;
date
2019-06-04
(1 row)
postgres=#
到此使用源碼來安裝pg數據庫就完成了。
Linux Oracle PostgreSQL
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。