环境:Linux localhost.localdomain 2.6.32-431 GNU/Linux x86_64

Postgresql版本:postgresql.9.5.3

添加开启自启设置:http://my.oschina.net/ensn/blog/690719

1.下载postgresql

因bz2格式包格式比较小,故选择该格式下载。地址:https://www.postgresql.org/ftp/source/v9.5.3/

2.安装:

2.1 解压:


tar jxvf postgresql-9.5.3.tar.bz2

2.2 安装:

查看INSTALL文件说明安装过程。

[root@localhost postgresql-9.5.3]# less INSTALL
PostgreSQL Installation from Source Code This document describes the installation of PostgreSQL using the source
code distribution. (If you are installing a pre-packaged distribution,
such as an RPM or Debian package, ignore this document and read the
packager's instructions instead.)
__________________________________________________________________ Short Version ./configure
make
su
make install
adduser postgres
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test
...

2.2.1 编译

在编译过程中可以指定安装目录与wal日记大小等。编译过程过程中如遇其他问题(可能是依赖库的问题),解决以后重新编译即可。关于编译指定参数与编译过程中可能碰到的问题可参考该博文


[root@localhost postgresql-9.5.3]# ./configure --prefix=/usr/local/pgsql9.5.3 --with-pgport=5432 --with-wal-blocksize=64
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether to build with 64-bit 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... 64kB
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... no
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 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 for grep that handles long lines and -e... /bin/grep
checking for egrep... /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... /bin/tar
checking whether ln -s works... yes
checking for gawk... gawk
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for bison... /usr/bin/bison
configure: using bison (GNU Bison) 2.4.1
checking for flex... /usr/bin/flex
configure: using flex 2.5.35
checking for perl... /usr/bin/perl
configure: using perl 5.10.1
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 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 whether gcc supports -Wl,--as-needed... yes
configure: using compiler=gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)
configure: using CFLAGS=-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -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/unix_latch.c to src/backend/port/pg_latch.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

2.2.2 安装:make & make install


[root@localhost postgresql-9.5.3]# make
make -C src all
make[1]: Entering directory `/home/ceg/postgresql-9.5.3/src'
make -C common all
make[2]: Entering directory `/home/ceg/postgresql-9.5.3/src/common'
make -C ../backend submake-errcodes
make[3]: Entering directory `/home/ceg/postgresql-9.5.3/src/backend'
prereqdir=`cd 'utils/' >/dev/null && pwd` && \
cd '../../src/include/utils/' && rm -f errcodes.h && \
ln -s "$prereqdir/errcodes.h" .
make[3]: Leaving directory `/home/ceg/postgresql-9.5.3/src/backend'
...
lm -o pg_regress
cp ../../../contrib/spi/refint.so refint.so
cp ../../../contrib/spi/autoinc.so autoinc.so
make[2]: Leaving directory `/home/ceg/postgresql-9.5.3/src/test/regress'
make[1]: Leaving directory `/home/ceg/postgresql-9.5.3/src'
make -C config all
make[1]: Entering directory `/home/ceg/postgresql-9.5.3/config'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/ceg/postgresql-9.5.3/config'
All of PostgreSQL successfully made. Ready to install. [root@localhost postgresql-9.5.3]# make install
make -C src install
make[1]: Entering directory `/home/ceg/postgresql-9.5.3/src'
make -C common install
make[2]: Entering directory `/home/ceg/postgresql-9.5.3/src/common'
make -C ../backend submake-errcodes
make[3]: Entering directory `/home/ceg/postgresql-9.5.3/src/backend'
make[3]: Nothing to be done for `submake-errcodes'.
make[3]: Leaving directory `/home/ceg/postgresql-9.5.3/src/backend'
.....
/bin/mkdir -p '/usr/local/pgsql9.5.3--with-pgport=5432/lib/pgxs/config'
/usr/bin/install -c -m 755 ./install-sh '/usr/local/pgsql9.5.3--with-pgport=5432/lib/pgxs/config/install-sh'
/usr/bin/install -c -m 755 ./missing '/usr/local/pgsql9.5.3--with-pgport=5432/lib/pgxs/config/missing'
make[1]: Leaving directory `/home/ceg/postgresql-9.5.3/config'
PostgreSQL installation complete.

3.创建数据库集群

3.1创建用户,用以配置环境变量与初始化数据库等。

[root@localhost pgsql9.5.3]# useradd postgres
[root@localhost pgsql9.5.3]# su - postgres
[postgres@localhost ~]$

 3.2 创建数据库集群

3.2.1 创建数据目录,并给postgres用户以权限

[root@localhost pgsql9.5.3]# mkdir data
[root@localhost pgsql9.5.3]# ll
总用量 20
drwxr-xr-x. 2 root root 4096 6月 13 11:17 bin
drwxr-xr-x. 2 root root 4096 6月 13 14:38 data
drwxr-xr-x. 6 root root 4096 6月 13 11:17 include
drwxr-xr-x. 4 root root 4096 6月 13 11:17 lib
drwxr-xr-x. 6 root root 4096 6月 13 11:17 share
[root@localhost pgsql9.5.3]# pwd
/usr/local/pgsql9.5.3
[root@localhost pgsql9.5.3]# chown -R postgres:postgres /usr/local/pgsql9.5.3/data

3.2.2 配置环境变量

在postgresql用户下配置环境变量只对postgres用户有效,如要对所有用户有效,配置profile。


[root@localhost ~]# su - postgres
[postgres@localhost ~]$ less ~/.bash_profile
# .bash_profile ... export PATH=/usr/local/pgsql9.5.3/bin:$PATH
LD_LIBRARY_PATH=/usr/local/pgsql9.5.3/lib
export LD_LIBRARY_PATH
export PGDATA=/usr/local/pgsql9.5.3/data
.... [postgres@localhost ~]$ source ~/.bash_profile
[postgres@localhost ~]$

3.2.3 初始化


[root@localhost pgsql9.5.3]# mkdir data
[root@localhost pgsql9.5.3]# ll
总用量 20
drwxr-xr-x. 2 root root 4096 6月 13 11:17 bin
drwxr-xr-x. 2 root root 4096 6月 13 14:38 data
drwxr-xr-x. 6 root root 4096 6月 13 11:17 include
drwxr-xr-x. 4 root root 4096 6月 13 11:17 lib
drwxr-xr-x. 6 root root 4096 6月 13 11:17 share
[root@localhost pgsql9.5.3]# pwd
/usr/local/pgsql9.5.3
[root@localhost pgsql9.5.3]# chown -R postgres:postgres /usr/local/pgsql9.5.3/data [root@localhost ~]# su - postgres
[postgres@localhost ~]$ echo $PGDATA
/usr/local/pgsql9.5.3/data
[postgres@localhost ~]$ pwd
[postgres@localhost ~]$ /usr/local/pgsql9.5.3/bin/initdb -E UTF8 -D $PGDATA --locale=C -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. fixing permissions on existing directory /usr/local/pgsql9.5.3/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
creating template1 database in /usr/local/pgsql9.5.3/data/base/1 ... ok
initializing pg_authid ... ok
Enter new superuser password:
Enter it again:
setting password ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... 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.5.3/bin/pg_ctl -D /usr/local/pgsql9.5.3/data -l logfile start

4. 启动数据库

4.1 配置postgresql.conf 和 pg_hba.conf。

4.2 启动数据库

[root@localhost ~]# su - postgres
[postgres@localhost data]$ pg_ctl start -D $PGDATA
server starting
[postgres@localhost data]$ LOG: redirecting log output to logging collector process
HINT: Future log output will appear in directory "pg_log". [postgres@localhost data]$
[postgres@localhost data]$ ps -ef|grep post
root 10092 367 0 15:32 pts/5 00:00:00 su - postgres
postgres 10093 10092 0 15:32 pts/5 00:00:00 -bash
postgres 11277 1 0 15:37 pts/5 00:00:00 /usr/local/pgsql9.5.3/bin/postgres -D /usr/local/pgsql9.5.3/data
postgres 11278 11277 0 15:37 ? 00:00:00 postgres: logger process
postgres 11280 11277 0 15:37 ? 00:00:00 postgres: checkpointer process
postgres 11281 11277 0 15:37 ? 00:00:00 postgres: writer process
postgres 11282 11277 0 15:37 ? 00:00:00 postgres: wal writer process
postgres 11283 11277 0 15:37 ? 00:00:00 postgres: autovacuum launcher process
postgres 11284 11277 0 15:37 ? 00:00:00 postgres: stats collector process

 4.3 登录数据库

[root@localhost pgsql9.5.3]# su - postgres
[postgres@localhost ~]$ psql
psql (9.5.3)
Type "help" for help. postgres=# \d
No relations found.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows) postgres=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

至此安装完毕。

本文是源码安装过程,该种安装方式可以在安装过程中配置一些参数。其他还有rmp等方式可参考博文1。原安装包中的各文件以及安装过程中的参数说明等可参考博文2

linux下安装postgresql的更多相关文章

  1. Linux下安装PostgreSQL 转载linux社区

    Linux下安装PostgreSQL [日期:2016-12-25] 来源:Linux社区  作者:xiaojian [字体:大 中 小]   在Linux下安装PostgreSQL有二进制格式安装和 ...

  2. linux 下安装PostgreSql 并配置远程访问

    1.官网下载PostgreSql 安装包 (https://www.enterprisedb.com/downloads/postgres-postgresql-downloads) 我下载的是 9. ...

  3. postgreSQL学习(一):在Linux下安装postgreSQL

    1. 安装源: $ sudo yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgd ...

  4. Linux下安装 Posgresql 并设置基本参数

    在Linux下安装Postgresql有二进制格式安装和源码安装两种安装方式,这里用的是二进制格式安装.各个版本的Linux都内置了Postgresql,所以可直接通过命令行安装便可.本文用的是Cen ...

  5. Linux CentOS安装postgresql 9.4

    一.前言 PostgreSQL通常也简称Postgres,是一个关系型数据库管理系统,适用于各种Linux操作系统.Windows.Solaris.BSD和Mac OS X.PostgreSQL遵循P ...

  6. CentOS 6.9下安装PostgreSQL

    操作系统:CentOS6.9_x64 PostgreSQL官方网址: https://www.postgresql.org/ 安装数据库 使用如下命令: yum install postgresql- ...

  7. Centos7下安装postgresql(tar包形式安装)

    Centos7下安装postgresql(tar包形式安装) 1.官网下载地址: https://www.postgresql.org/ftp/source/ 2.将下载来tar包上传到linux服务 ...

  8. Linux下安装Tomcat服务器和部署Web应用

    一.上传Tomcat服务器

  9. Linux下安装使用Solr

    Linux下安装使用Solr 1.首先下载Solr.mmseg4j分词包.tomcat并解压,这用google.百度都可以搜索得到下载地址. 2.因为要使用到中文分词,所以要设置编码,进入tomcat ...

随机推荐

  1. 30天的php学习之路——第一天开端

    因项目紧急只留给了我4周时间学习php.谨以此文记录我的php学习历程,仅供参考,若有错误请指正. 之前对php有过一些了解,一些语法和习惯和C#差距有些大,所以第一天准备对php中的符号有个全面的了 ...

  2. 微软本月将推Win10 望打破Win8所带来差评影响

    系统妈 据香港“文汇报”7月15日报道,美国电脑巨擘微软13日宣布,新视窗系统10(Windows 10)将于7月29日推出.微软高层迈赫迪在网志表示,届时全球将有13个城市举办特别活动,表扬参与Wi ...

  3. jquery each函数 break和continue功能

    jquery each函数 break和continue功能幸运的是另一个突破,持续一个jQuery循环方式.你可以打破在函数返回一个jQuery参数虚假循环.一个可以继续执行只是在做不指定返回值或返 ...

  4. [LeetCode] Paint House II 粉刷房子之二

    There are a row of n houses, each house can be painted with one of the k colors. The cost of paintin ...

  5. Socket通信综合示例

    1用户注册客户单选择'用户注册',提示要输入用户名,密码,确认密码,校验成功后将用户信息保存到数据库,并提示数据库注册成功,请登录2用户登录客户端选择'登录以后'后,提示输入用户名和密码,验证成功则提 ...

  6. SpringMVC注解汇总(二)-请求映射规则

    接上一节SpringMVC注解汇总-定义 讲到Httpy请求信息 URL路径映射 1)普通URL路径映射 @RequestMapping(value={"/test1", &quo ...

  7. Gradle 下载

    gradle各个版本的下载地址 :http://services.gradle.org/distributions 下载完后的gradle怎么使用呢? //下面是网上提供的方法,仅供学习参考 在 ht ...

  8. oracle新建登录用户sql语句

    CREATE TABLESPACE TEST_DBDATAFILE '/mnt/data/oracledata/TEST_DB .dbf' SIZE 5000M AUTOEXTEND ONUNIFOR ...

  9. iOS 安装应用

    1.itool 安装 不是本文重点 2.fruitstrap安装 2.1 前往 https://github.com/ghughes/fruitstrap 下载源代码 (git clone 即可) 2 ...

  10. Beta阶段测试报告

    前端测试计划 具体测试项如下: 注册测试 登录测试 忘记密码测试 一次登录后自动登录测试 退出登录测试 编辑资料测试 查看好友测试 搜索好友测试 添加好友测试 获取当前正在游戏的房间测试 创建房间测试 ...