在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数据库就完成了。
在Oracle Linux 7.1中使用源码来安装PostgreSQL 9.6
来源:这里教程网
时间:2026-03-14 19:38:15
作者:
编辑推荐:
下一篇:
相关推荐
-
雷神推出 MIX PRO II 迷你主机:基于 Ultra 200H,玻璃上盖 + ARGB 灯效
2 月 9 日消息,雷神 (THUNDEROBOT) 现已宣布推出基于英
-
制造商 Musnap 推出彩色墨水屏电纸书 Ocean C:支持手写笔、第三方安卓应用
2 月 10 日消息,制造商 Musnap 现已在海外推出一款 Oce
热文推荐
- How to Optimize PostgreSQL Logical Replication
- 电脑的基本操作知识大全
电脑的基本操作知识大全
26-03-14 - PostgreSQL DBA(43) - Index(Hash)
PostgreSQL DBA(43) - Index(Hash)
26-03-14 - PostgreSQL pg_rewind实例--could not find previous WAL record at %X/%X
- 为什么PostgreSQL越来越火?
为什么PostgreSQL越来越火?
26-03-14 - Word显示网格线(多版本)
Word显示网格线(多版本)
26-03-14 - RockyLinux网络配置与管理(RockyLinux网络最佳实践指南)
- 新手电脑入门基础知识大全
新手电脑入门基础知识大全
26-03-14 - RockyLinux文件共享高可用配置(基于DRBD+Pacemaker+NFS实现企业级高可用存储)
- PostgreSQL GUI pgadmin4 v3.3 支持 gis geometry 数据编辑、显示
