在Oracle Linux 7.1中使用原始碼來安裝PostgreSQL 9.6
在Oracle Linux 7.1中使用原始碼來安裝PostgreSQL 9.6
編譯PostgreSQL需要下列軟體包:
1.GUN make版本3.80或新的要求。
[root@cs1 /]# make --version
GNU Make 3.82
Built for x86-redhat-linux-gnu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
2.需要一個ISO/ANSI C 編譯器(至少是 C89相容的)。我們推薦使用最近版本的GCC
[root@cs1 /]# gcc --version
gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9)
Copyright (C) 2013 Free Software Foundation, Inc.
本程式是自由軟體;請參看原始碼的版權宣告。本軟體沒有任何擔保;
包括沒有適銷性和某一專用目的下的適用性擔保。
3.除了gzip和bzip2之外,我們還需要tar來解包原始碼釋出。
4.GNU Readline庫
[root@cs1 /]# rpm -aq | grep readline
readline-6.2-9.el7.x86[root@cs1 /]# rpm -aq | grep readline-deve
readline-devel-6.2-9.el7.x86[root@cs1 /]# rpm -aq | grep libedit
libedit-3.0-12.20121213cvs.el7.x86
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 postgresql-9.6.6.tar.gz
建立一個軟連結
[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 libdrwxr-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
lrwxrwxrwx 1 root root 38 6月 4 14:43 mysql -> mariadb-10.0.38-linux-glibc_214-x86
lrwx
rwxrwx 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-pc-linux-gnu
checking host system type... x86-pc-linux-gnu
checking which template to use... linux
checking whether to build with - integer date/time support... yes
checking whether NLS is wanted... no
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for WAL segment size... 16MB
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc supports -Wdeclaration-after-statement... yes
checking whether gcc supports -Wendif-labels... yes
checking whether gcc supports -Wmissing-format-attribute... yes
checking whether gcc supports -Wformat-security... yes
checking whether gcc supports -fno-strict-aliasing... yes
checking whether gcc supports -fwrapv... yes
checking whether gcc supports -fexcess-precision=standard... yes
checking whether gcc supports -funroll-loops... yes
checking whether gcc supports -ftree-vectorize... yes
checking whether gcc supports -Wunused-command-line-argument... no
checking whether the C compiler still works... yes
checking how to run the C preprocessor... gcc -E
checking allow thread-safe client libraries... yes
checking whether to build with Tcl... no
checking whether to build Perl modules... no
checking whether to build Python modules... no
checking whether to build with GSSAPI support... no
checking whether to build with PAM support... no
checking whether to build with BSD Authentication support... no
checking whether to build with LDAP support... no
checking whether to build with Bonjour support... no
checking whether to build with OpenSSL support... no
checking whether to build with SELinux support... no
checking whether to build with systemd support... no
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ld used by GCC... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for ranlib... ranlib
checking for strip... strip
checking whether it is possible to strip libraries... yes
checking for ar... ar
checking for a BSD-compatible install... /usr/bin/install -c
checking for tar... /usr/bin/tar
checking whether ln -s works... yes
checking for gawk... gawk
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for bison... /usr/bin/bison
configure: using bison (GNU Bison) 2.7
checking for flex... /usr/bin/flex
configure: using flex 2.5.37
checking for perl... /usr/bin/perl
configure: using perl 5.16.3
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking if compiler needs certain flags to reject unknown flags... no
checking for the pthreads library -lpthreads... no
checking whether pthreads work without any flags... no
checking whether pthreads work with -Kthread... no
checking whether pthreads work with -kthread... no
checking for the pthreads library -llthread... no
checking whether pthreads work with -pthread... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking if more special flags are required for pthreads... no
checking for PTHREAD_PRIO_INHERIT... yes
checking pthread.h usability... yes
checking pthread.h presence... yes
checking for pthread.h... yes
checking for strerror_r... yes
checking for getpwuid_r... yes
checking for gethostbyname_r... yes
checking whether strerror_r returns int... no
checking for main in -lm... yes
checking for library containing setproctitle... no
checking for library containing dlopen... -ldl
checking for library containing socket... none required
checking for library containing shl_load... no
checking for library containing getopt_long... none required
checking for library containing crypt... -lcrypt
checking for library containing shm_open... -lrt
checking for library containing shm_unlink... none required
checking for library containing fdatasync... none required
checking for library containing sched_yield... none required
checking for library containing gethostbyname_r... none required
checking for library containing shmget... none required
checking for library containing readline... -lreadline
checking for inflate in -lz... yes
checking atomic.h usability... no
checking atomic.h presence... no
checking for atomic.h... no
checking crypt.h usability... yes
checking crypt.h presence... yes
checking for crypt.h... yes
checking dld.h usability... no
checking dld.h presence... no
checking for dld.h... no
checking fp_class.h usability... no
checking fp_class.h presence... no
checking for fp_class.h... no
checking getopt.h usability... yes
checking getopt.h presence... yes
checking for getopt.h... yes
checking ieeefp.h usability... no
checking ieeefp.h presence... no
checking for ieeefp.h... no
checking ifaddrs.h usability... yes
checking ifaddrs.h presence... yes
checking for ifaddrs.h... yes
checking langinfo.h usability... yes
checking langinfo.h presence... yes
checking for langinfo.h... yes
checking mbarrier.h usability... no
checking mbarrier.h presence... no
checking for mbarrier.h... no
checking poll.h usability... yes
checking poll.h presence... yes
checking for poll.h... yes
checking pwd.h usability... yes
checking pwd.h presence... yes
checking for pwd.h... yes
checking sys/epoll.h usability... yes
checking sys/epoll.h presence... yes
checking for sys/epoll.h... yes
checking sys/ioctl.h usability... yes
checking sys/ioctl.h presence... yes
checking for sys/ioctl.h... yes
checking sys/ipc.h usability... yes
checking sys/ipc.h presence... yes
checking for sys/ipc.h... yes
checking sys/poll.h usability... yes
checking sys/poll.h presence... yes
checking for sys/poll.h... yes
checking sys/pstat.h usability... no
checking sys/pstat.h presence... no
checking for sys/pstat.h... no
checking sys/resource.h usability... yes
checking sys/resource.h presence... yes
checking for sys/resource.h... yes
checking sys/select.h usability... yes
checking sys/select.h presence... yes
checking for sys/select.h... yes
checking sys/sem.h usability... yes
checking sys/sem.h presence... yes
checking for sys/sem.h... yes
checking sys/shm.h usability... yes
checking sys/shm.h presence... yes
checking for sys/shm.h... yes
checking sys/socket.h usability... yes
checking sys/socket.h presence... yes
checking for sys/socket.h... yes
checking sys/sockio.h usability... no
checking sys/sockio.h presence... no
checking for sys/sockio.h... no
checking sys/tas.h usability... no
checking sys/tas.h presence... no
checking for sys/tas.h... no
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking sys/un.h usability... yes
checking sys/un.h presence... yes
checking for sys/un.h... yes
checking termios.h usability... yes
checking termios.h presence... yes
checking for termios.h... yes
checking ucred.h usability... no
checking ucred.h presence... no
checking for ucred.h... no
checking utime.h usability... yes
checking utime.h presence... yes
checking for utime.h... yes
checking wchar.h usability... yes
checking wchar.h presence... yes
checking for wchar.h... yes
checking wctype.h usability... yes
checking wctype.h presence... yes
checking for wctype.h... yes
checking for net/if.h... yes
checking for sys/ucred.h... no
checking netinet/in.h usability... yes
checking netinet/in.h presence... yes
checking for netinet/in.h... yes
checking for netinet/tcp.h... yes
checking readline/readline.h usability... yes
checking readline/readline.h presence... yes
checking for readline/readline.h... yes
checking readline/history.h usability... yes
checking readline/history.h presence... yes
checking for readline/history.h... yes
checking zlib.h usability... yes
checking zlib.h presence... yes
checking for zlib.h... yes
checking whether byte ordering is bigendian... no
checking for inline... inline
checking for printf format archetype... gnu_printf
checking for flexible array members... yes
checking for signed types... yes
checking for __func__... yes
checking for _Static_assert... yes
checking for __builtin_types_compatible_p... yes
checking for __builtin_bswap32... yes
checking for __builtin_bswap... yes
checking for __builtin_constant_p... yes
checking for __builtin_unreachable... yes
checking for __VA_ARGS__... yes
checking whether struct tm is in sys/time.h or time.h... time.h
checking for struct tm.tm_zone... yes
checking for tzname... yes
checking for union semun... no
checking for struct sockaddr_un... yes
checking for struct sockaddr_storage... yes
checking for struct sockaddr_storage.ss_family... yes
checking for struct sockaddr_storage.__ss_family... no
checking for struct sockaddr_storage.ss_len... no
checking for struct sockaddr_storage.__ss_len... no
checking for struct sockaddr.sa_len... no
checking for struct addrinfo... yes
checking for intptr_t... yes
checking for uintptr_t... yes
checking for unsigned long long int... yes
checking for long long int... yes
checking for locale_t... yes
checking for struct cmsgcred... no
checking for struct option... yes
checking for z_streamp... yes
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... no
checking size of off_t... 8
checking for int timezone... yes
checking types of arguments for accept()... int, int, struct sockaddr *, socklen_t *
checking whether gettimeofday takes only one argument... no
checking for wcstombs_l declaration... no
checking for cbrt... yes
checking for dlopen... yes
checking for fdatasync... yes
checking for getifaddrs... yes
checking for getpeerucred... no
checking for getrlimit... yes
checking for mbstowcs_l... no
checking for memmove... yes
checking for poll... yes
checking for posix_fallocate... yes
checking for pstat... no
checking for pthread_is_threaded_np... no
checking for readlink... yes
checking for setproctitle... no
checking for setsid... yes
checking for shm_open... yes
checking for symlink... yes
checking for sync_file_range... yes
checking for towlower... yes
checking for utime... yes
checking for utimes... yes
checking for wcstombs... yes
checking for wcstombs_l... no
checking for fseeko... yes
checking for _LARGEFILE_SOURCE value needed for large files... no
checking for posix_fadvise... yes
checking whether posix_fadvise is declared... yes
checking whether fdatasync is declared... yes
checking whether strlcat is declared... no
checking whether strlcpy is declared... no
checking whether F_FULLFSYNC is declared... no
checking for struct sockaddr_in6... yes
checking for PS_STRINGS... no
checking for snprintf... yes
checking for vsnprintf... yes
checking whether snprintf is declared... yes
checking whether vsnprintf is declared... yes
checking for isinf... yes
checking for crypt... yes
checking for fls... no
checking for getopt... yes
checking for getrusage... yes
checking for inet_aton... yes
checking for mkdtemp... yes
checking for random... yes
checking for rint... yes
checking for srandom... yes
checking for strerror... yes
checking for strlcat... no
checking for strlcpy... no
checking for unsetenv... yes
checking for getpeereid... no
checking for getaddrinfo... yes
checking for getopt_long... yes
checking whether sys_siglist is declared... yes
checking for syslog... yes
checking syslog.h usability... yes
checking syslog.h presence... yes
checking for syslog.h... yes
checking for opterr... yes
checking for optreset... no
checking for strtoll... yes
checking for strtoull... yes
checking for rl_completion_append_character... yes
checking for rl_completion_matches... yes
checking for rl_filename_completion_function... yes
checking for rl_reset_screen_size... yes
checking for append_history... yes
checking for history_truncate_file... yes
checking test program... ok
checking whether long int is bits... yes
checking whether snprintf supports the %z modifier... yes
checking size of void *... 8
checking size of size_t... 8
checking size of long... 8
checking whether to build with float4 passed by value... yes
checking whether to build with float8 passed by value... yes
checking alignment of short... 2
checking alignment of int... 4
checking alignment of long... 8
checking alignment of double... 8
checking for int8... no
checking for uint8... no
checking for int... no
checking for uint... no
checking for __int128... yes
checking for builtin __sync char locking functions... yes
checking for builtin __sync int32 locking functions... yes
checking for builtin __sync int32 atomic operations... yes
checking for builtin __sync int atomic operations... yes
checking for builtin __atomic int32 atomic operations... yes
checking for builtin __atomic int atomic operations... yes
checking for __get_cpuid... yes
checking for __cpuid... no
checking for _mm_crc32_u8 and _mm_crc32_u32 with CFLAGS=... no
checking for _mm_crc32_u8 and _mm_crc32_u32 with CFLAGS=-msse4.2... yes
checking which CRC-32C implementation to use... SSE 4.2 with runtime check
checking for onsgmls... no
checking for nsgmls... no
checking for openjade... no
checking for jade... no
checking for DocBook V4.2... no
checking for DocBook stylesheets... no
checking for collateindex.pl... no
checking for dbtoepub... no
checking for xmllint... xmllint
checking for xsltproc... xsltproc
checking for osx... no
checking for sgml2xml... no
checking for sx... sx
checking thread safety of required library functions... yes
checking whether gcc supports -Wl,--as-needed... yes
configure: using compiler=gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9)
configure: using CFLAGS=-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2
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=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export LD_LIBRARY_PATH=/usr/local/pgsql/lib
export PG_HOME=/usr/local/pgsql
export PATH=$PG_HOME/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@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 392 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 392 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
從資料庫日誌檔案可以看到如下資訊:
[root@cs1 log]# tail -f pg_server.log
LOG: database system was shut down at 2019-06-04 21:56:12 CST
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
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-pc-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), -bit
(1 row)
postgres=# select current_date;
date
------------
2019-06-04
(1 row)
postgres=#
到此使用原始碼來安裝pg資料庫就完成了。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26015009/viewspace-2646772/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Linux下PostgreSQL原始碼安裝LinuxSQL原始碼
- 【PG安裝】postgresql10 for linux 原始碼安裝SQLLinux原始碼
- Linux使用原始碼來安裝MySQL 5.7Linux原始碼MySql
- 原始碼安裝postgresql原始碼SQL
- PostgreSQL在Linux下安裝與使用SQLLinux
- 在Linux上安裝postgresqlLinuxSQL
- 在 Linux 上安裝 PostgreSQLLinuxSQL
- PostgreSQL-原始碼安裝(一)SQL原始碼
- openeuler原始碼安裝Postgresql 16原始碼SQL
- PostgreSQL 10.12 安裝系列 - 原始碼安裝SQL原始碼
- postgreSQL學習(一):在Linux下安裝postgreSQLSQLLinux
- 在 Ubuntu 上使用原始碼安裝 OpenRestyUbuntu原始碼REST
- postgresql 12.5軟體原始碼安裝SQL原始碼
- postgresql原始碼安裝man的內容SQL原始碼
- postgresql原始碼安裝contribSQL原始碼
- 使用免安裝版本在windows上手動安裝PostgreSQLWindowsSQL
- PostgreSQL技術大講堂 - Part 2:PostgreSQL原始碼安裝SQL原始碼
- PostgreSQL原始碼學習 win10原始碼編譯安裝SQL原始碼Win10編譯
- linux 非root使用者原始碼安裝Linux原始碼
- POSTGRESQL10.8原始碼安裝主從搭建SQL原始碼
- POSTGRESQL10.3原始碼安裝主從搭建SQL原始碼
- Mysql for Linux安裝配置之—— 原始碼安裝MySqlLinux原始碼
- MySQL在CentOS 6.4 原始碼安裝MySqlCentOS原始碼
- 在linux下安裝oracle bbedLinuxOracle
- Oracle在Linux上的安裝OracleLinux
- Linux 原始碼方式安裝zipLinux原始碼
- linux安裝python3(原始碼安裝)LinuxPython原始碼
- PostgreSQL 13 原始碼安裝(#1.1)-202103SQL原始碼
- Postgresql Linux版本安裝——RPM包安裝SQLLinux
- linux mysql 安裝步驟- 原始碼安裝5.7.17 版本LinuxMySql原始碼
- 在Oracle Linux 7.1上安裝DockerOracleLinuxDocker
- Oracle BIEE在linux下的安裝OracleLinux
- linux下LAMP原始碼安裝部署LinuxLAMP原始碼
- linux下從原始碼安裝gitLinux原始碼Git
- mysql-5.1.68-linux原始碼安裝MySqlLinux原始碼
- linux中原始碼編譯安裝Linux原始碼編譯
- MySQL5.6 linux原始碼安裝MySqlLinux原始碼
- Oracle與PostgreSQL比較:PostgreSQL至少在安裝和大小方面擊敗了Oracle - foersterOracleSQL