为什么80%的码农都做不了架构师?>>>   

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

Postgresql版本:postgresql.9.5.3

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 INSTALLPostgreSQL Installation from Source CodeThis document describes the installation of PostgreSQL using the sourcecode distribution. (If you are installing a pre-packaged distribution,such as an RPM or Debian package, ignore this document and read thepackager'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 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 ~]# su - postgres
[postgres@localhost ~]$ echo $PGDATA
/usr/local/pgsql9.5.3/data
[postgres@localhost ~]$ pwd
/home/postgres
[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:         --note:postgres
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 ... okWARNING: 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=# \lList of databasesName    |  Owner   | Encoding | Collate | Ctype |   Access privileges
-----------+----------+----------+---------+-------+-----------------------postgres  | postgres | UTF8     | C       | C     | template0 | postgres | UTF8     | C       | C     | =c/postgres          +|          |          |         |       | postgres=CTc/postgrestemplate1 | postgres | UTF8     | C       | C     | =c/postgres          +|          |          |         |       | postgres=CTc/postgres
(3 rows)postgres=# \duList of rolesRole name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

至此安装完毕。

4.4 设置开启自启

服务正常或者异常产生的重启都需要重启postgres,可通过设置linux启动项设置自启动, PostgreSQL的开机自启动脚本位于PostgreSQL源码目录的contrib/start-scripts路径下 ,

[root@localhost contrib]# ll |grep start-scripts
drwxrwxrwx. 3 1107 1107  4096 5月  10 05:05 start-scripts
[root@localhost contrib]# cd start-scripts
[root@localhost start-scripts]# ll
总用量 12
-rw-r--r--. 1 1107 1107 1529 5月  10 04:50 freebsd
-rw-r--r--. 1 1107 1107 3642 5月  10 04:50 linux
drwxrwxrwx. 2 1107 1107 4096 5月  10 05:05 osx

linux即为开机启动脚本文件,文件包含设置说明:

[root@localhost start-scripts]# less linux
#! /bin/sh# chkconfig: 2345 98 02
# description: PostgreSQL RDBMS# This is an example of a start/stop script for SysV-style init, such
# as is used on Linux systems.  You should edit some of the variables
# and maybe the 'echo' commands.
#
# Place this file at /etc/init.d/postgresql (or
# /etc/rc.d/init.d/postgresql) and make symlinks to
#   /etc/rc.d/rc0.d/K02postgresql
#   /etc/rc.d/rc1.d/K02postgresql
#   /etc/rc.d/rc2.d/K02postgresql
#   /etc/rc.d/rc3.d/S98postgresql
#   /etc/rc.d/rc4.d/S98postgresql
#   /etc/rc.d/rc5.d/S98postgresql
# Or, if you have chkconfig, simply:
# chkconfig --add postgresql
#
# Proper init scripts on Linux systems normally require setting lock
# and pid files under /var/run as well as reacting to network
# settings, so you should treat this with care.# Original author:  Ryan Kirkpatrick <pgsql@rkirkpat.net># contrib/start-scripts/linux
....

4.4.1 修改linux文件属性,添加X属性

[root@localhost start-scripts]# chmod a+x linux 

4.4.2 复制linux文件到/etc/init.d目录下,更名为postgresql

[root@localhost start-scripts]# cp linux  /etc/init.d/postgresql

4.4.3  修改/etc/init.d/postgresql文件的两个变量

prefix设置为postgresql的安装路径,PGDATA设置为postgresql的数据目录路径:

     29 ## EDIT FROM HERE30 31 # Installation prefix32 #prefix=/usr/local/pgsql33 prefix=/usr/local/pgsql9.5.334 35 # Data directory36 PGDATA="/usr/local/pgsql9.5.3/data"

4.4.4 重启数据库服务

[root@localhost init.d]# service postgresql stop
Stopping PostgreSQL: ok
[root@localhost init.d]# service postgresql start
Starting PostgreSQL: ok

4.4.5 添加到启动项

[root@localhost init.d]# chkconfig --add postgresql
[root@localhost init.d]# chkconfig --list|grep postgres
postgresql      0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

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

转载于:https://my.oschina.net/ensn/blog/690719

Linux 下安装Postgresql相关推荐

  1. linux下安装 postgresql 14

    一,linux下安装postgresql         PostgreSQL: Linux downloads (Red Hat family) https://www.postgresql.org ...

  2. Linux下安装PostgreSQL

    Linux下安装PostgreSQL 一.PostgreSQL简介 二.Linux 上安装 PostgreSQL 1.二进制已编绎安装包方式安装 (1)下载二进制包 (2)创建postgres用户 ( ...

  3. linux怎么编译并安装busybox,linux下安装busybox

    1.获取busybox源码并解压,这里使用天嵌提供的"busybox-1.16.0.tar.bz2" #tar xvf busybox-1.16..tar.bz2 -C / 解压的 ...

  4. linux blender骨骼绑定,Linux下安装Blender

    Blender在Windows下,可以在官方直接下载免安装的版本,下载解压缩就能用. 在Linux下稍微麻烦一点点. 如下3步安装的blender不一定是最新版本,且安装完成后发现设置中文会变为方块. ...

  5. wsock32 linux,在linux下安装并使用websocket

    前言 首先,对websocket要有一个简要的了解与认识 websocket是HTML5开始提供的一种浏览器与服务器进行全双工通讯的网络技术,属于应用层协议. 它基于TCP传输协议,并复用HTTP的握 ...

  6. CentOS 6.9下安装PostgreSQL

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

  7. 短小视频网站sexcms源码 安装搭建环境加采集教程 有手机和PC演示站 linux下安装一片空白的解决linux下安装一片空白的解决

    特别注意:在linux下安装一片空白的解决方法:把index.php的第66行改为require_once sexPATH.'lib/Cs_Sex.php';就行.linux下要注意大小写区分. 电脑 ...

  8. linux postgresql 创建数据库,Linux下创建Postgresql数据库的方法步骤

    Linux下创建Postgresql数据库的方法步骤 前言 PostgreSQL (也叫 Postgres)是一个自由的对象-关系数据库服务器(数据库管理系统),它在灵活的 BSD-风格许可证下发行. ...

  9. linux下安装sbt_如何在Linux上安装SBT

    linux下安装sbt 介绍 (Introduction) Hi! I am Sanjula, and in this guide I hope to teach you how to install ...

最新文章

  1. 包云岗:关于RISC-V成为印度国家指令集的一些看法
  2. PyTorch手把手自定义Dataloader读取数据
  3. 《因果科学周刊》第1期:因果社区诚邀加入,打造因果推理共同范式
  4. Spring Security –在一个应用程序中有两个安全领域
  5. HTTP与HTTPS的区别[转载]
  6. python 多关键字匹配_使用django的objects.filter()方法匹配多个关键字的方法
  7. Python——五分钟理解函数式编程与闭包
  8. 树莓派学习之路-GPIO Zero
  9. digest 用户认证 response生成算法
  10. 【Asp.Net】C#中checked关键字的应用
  11. 笨办法学 Python · 续 练习 47:`bc`
  12. Shell 概述、截取字符操作等
  13. Spring提供的iBatis的SqlMap配置
  14. 永久解决VSCode终端中文乱码问题
  15. 论文 查重 知网 万方 paperpass
  16. 【spring】自定义AOP切面
  17. 500个爆文标题_总结了500篇10W+爆文 好标题都离不开以下几点
  18. 吃饭 睡觉 打豆豆游戏
  19. 几道经典的面试题53
  20. 【RT-Thread】nxp rt10xx 设备驱动框架之--adc搭建和使用

热门文章

  1. JavaScript正则表达式使用详解
  2. 【ROS学习笔记】(三)发布者Publisher的实现
  3. python处理音频的库_Python中音频处理库pydub的使用教程
  4. linux vim命令,linux之vim命令
  5. 支持mysql8的客户端_mysql8 参考手册--mysql客户端帮助
  6. getset原子性 redis_RedisAPI原子性操作及原理解析
  7. 计算机组成原理中计算机主要包括哪几部分,计算机组成原理本科生期末试卷(五)部分答案详解...
  8. 在R中创建晶须和盒图
  9. c ++异常处理_C ++中的异常处理
  10. textswitcher_Android TextSwitcher和ImageSwitcher示例教程