PostgreSQL学习笔记(一) ubuntu 16.4 源码安装 PostgreSQL 10
1.首先要解决所需的先决条件,必须安装下列软件包
apt install gcc zlib1g-dev libreadline6-dev
2.通过wget从官网下载安装介质
wget -c https://ftp.postgresql.org/pub/source/v10.0/postgresql-10.0.tar.bz2
3.使用tar命令解压安装包
tar -xvf postgresql-10.0.tar.bz2
4.配置下载的源代码
cd postgresql-10.0
5.创建安装目录,并在配置中选择prefix选项指定安装的目录.
root@buddy-yuan:/tmp/postgresql-10.0# ./configure --help
`configure' configures PostgreSQL 10.0 to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print `checking ...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or `..']
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local/pgsql]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
root@buddy-yuan:/tmp/postgresql-10.0# mkdir /opt/PostgreSQL-10
root@buddy-yuan:/tmp/postgresql-10.0# ./configure --prefix=/opt/PostgreSQL-10/
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/posix_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
6.使用make命令构建postgreSQL,构建完成之后进行安装
make
make install
make[1]: Entering directory '/tmp/postgresql-10.0/config'
/bin/mkdir -p '/opt/PostgreSQL-10/lib/postgresql/pgxs/config'
/usr/bin/install -c -m 755 ./install-sh '/opt/PostgreSQL-10/lib/postgresql/pgxs/config/install-sh'
/usr/bin/install -c -m 755 ./missing '/opt/PostgreSQL-10/lib/postgresql/pgxs/config/missing'
make[1]: Leaving directory '/tmp/postgresql-10.0/config'
PostgreSQL installation complete.
7.创建postgre用户和创建数据库数据存放目录
root@buddy-yuan:/tmp/postgresql-10.0# useradd -d /home/postgres postgres
root@buddy-yuan:/tmp/postgresql-10.0# passwd postgres
root@buddy-yuan:/tmp/postgresql-10.0# mkdir /pgdata
root@buddy-yuan:/tmp/postgresql-10.0# mkdir -p /pgdata/data
root@buddy-yuan:/tmp/postgresql-10.0# chown -R postgres. /pgdata/data/
echo 'export PATH=$PATH:/opt/PostgreSQL-10/bin' > /etc/profile.d/postgres.sh
8.初始化数据库
$ initdb -D /pgdata/data/ -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 "zh_CN.UTF-8".
The default database encoding has accordingly been set to "UTF8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".
Data page checksums are disabled.
Enter new superuser password:
Enter it again:
fixing permissions on existing directory /pgdata/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 /pgdata/data/ -l logfile start
9.修改postgresql.conf配置文件,启动数据库
listen_addresses = 'localhost' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
$ mkdir -p /pgdata/data/logs
$ pg_ctl -D /pgdata/data/ -l /pgdata/data/logs/start.log start
waiting for server to start.... done
server started
10.验证数据库状态并连接
$ psql -p 5432
psql (10.0)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 |
template0 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
Post a Comment