PostgreSQL installation on Ubuntu

本文详细介绍了从下载到安装PostgreSQL数据库的过程,并通过在Ubuntu系统上进行配置,最终实现数据库的成功部署。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. download from http://www.postgresql.org

2. Install PostgreSQL on Ubuntu

test:/DB# tar zxf postgresql-9.1.8.tar.gz
test:/DB# ls
postgresql-9.1.8  postgresql-9.1.8.tar.gz
test:/DB# cd postgresql-9.1.8
test:/DB/postgresql-9.1.8#./configure --without-readline
mock `ln -s conf26845.file conf26845` to `cp  conf26845.file conf26845`
mock `ln -s conf26845.file conf26845.dir` to `cp  conf26845.file conf26845.dir`
checking build system type... i686-pc-linux-gnu
....

checking zlib.h usability... yes
checking zlib.h presence... yes
checking for zlib.h... yes
.....

config.status: linking src/makefiles/Makefile.linux to src/Makefile.port
mock `ln -s ../src/makefiles/Makefile.linux src/Makefile.port` to `cp  ../src/makefiles/Makefile.linux src/Makefile.port`
mock `ln src/makefiles/Makefile.linux src/Makefile.port` to `cp  src/makefiles/Makefile.linux src/Makefile.port`
test:/DB/postgresql-9.1.8#make
make -C src all
make[1]: Entering directory `/media/shared/DB/postgresql-9.1.8/src'
make -C port all
make[2]: Entering directory `/media/shared/DB/postgresql-9.1.8/src/port'
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -I../../src/port -DFRONTEND -I../../src/include -D_GNU_SOURCE   -c -o strlcat.o strlcat.c
......

make -C config all
make[1]: Entering directory `/media/shared/DB/postgresql-9.1.8/config'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/media/shared/DB/postgresql-9.1.8/config'
All of PostgreSQL successfully made. Ready to install.
test:/DB/postgresql-9.1.8#make install
make -C src install
make[1]: Entering directory `/media/shared/DB/postgresql-9.1.8/src'
make -C port install
make[2]: Entering directory `/media/shared/DB/postgresql-9.1.8/src/port'
make -C ../backend submake-errcodes
make[3]: Entering directory `/media/shared/DB/postgresql-9.1.8/src/backend'
make[3]: Nothing to be done for `submake-errcodes'.
.....

make[1]: Leaving directory `/media/shared/DB/postgresql-9.1.8/src'
make -C config install
make[1]: Entering directory `/media/shared/DB/postgresql-9.1.8/config'
/bin/mkdir -p '/usr/local/pgsql/lib/pgxs/config'
/bin/sh ../config/install-sh -c -m 755 ./install-sh '/usr/local/pgsql/lib/pgxs/config/install-sh'
make[1]: Leaving directory `/media/shared/DB/postgresql-9.1.8/config'
PostgreSQL installation complete.
test:/DB/postgresql-9.1.8#useradd postgresuser
test:/DB/postgresql-9.1.8# ls /usr/local/pgsql
bin  include  lib  share
test:/DB/postgresql-9.1.8# mkdir /usr/local/pgsql/data
test:/DB/postgresql-9.1.8#chown postgresuser /usr/local/pgsql/data
test:/DB/postgresql-9.1.8#su -postgresuser
No directory, logging in with HOME=/
$ ls /usr/local/pgsql/bin
clusterdb   dropdb    initdb       pg_ctl     pg_restore reindexdb
createdb    droplang  pg_basebackup   pg_dump     postgres vacuumdb
createlang  dropuser  pg_config       pg_dumpall    postmaster
createuser  ecpg      pg_controldata  pg_resetxlog  psql
$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
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 en_US.UTF-8.
The default database encoding has accordingly been set to UTF8.
The default text search configuration will be set to "english".

fixing permissions on existing directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 24MB
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/data/base/1 ... ok
initializing pg_authid ... 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

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.

Success. You can now start the database server using:

    /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
or
    /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start

$ cd /usr/local/pgsql/data
$ ls
base  pg_hba.conf pg_notify    pg_subtrans  PG_VERSION
global  pg_ident.conf pg_serial    pg_tblspc   pg_xlog
pg_clog  pg_multixact pg_stat_tmp  pg_twophase  postgresql.conf
$ vi pg_hba.conf

host    all             all             192.168.0.0/16            trust

$ ls
base  pg_hba.conf pg_notify    pg_subtrans  PG_VERSION
global  pg_ident.conf pg_serial    pg_tblspc   pg_xlog
pg_clog  pg_multixact pg_stat_tmp  pg_twophase  postgresql.conf
$ pwd
/usr/local/pgsql/data
$ vi postgresql.conf  

listen_addresses=’*'
$ /usr/local/pgsql/bin/postmaster -i -D /usr/local/pgsql/data > logfile 2>&1 &
$ cat logfile
LOG:  database system was shut down at 2013-02-18 17:27:54 CST
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started
$ /usr/local/pgsql/bin/psql
psql (9.1.8)
Type "help" for help.

postgres-#    \?
General
  \copyright             show PostgreSQL usage and distribution terms
  \g [FILE] or ;         execute query (and send results to file or |pipe)
  \h [NAME]              help on syntax of SQL commands, * for all commands
  \q                     quit psql

Query Buffer
  \e [FILE] [LINE]       edit the query buffer (or file) with external editor
  \ef [FUNCNAME [LINE]]  edit function definition with external editor
  \p                     show the contents of the query buffer
  \r                     reset (clear) the query buffer
  \w FILE                write query buffer to file

Input/Output
  \copy ...              perform SQL COPY with data stream to the client host
  \echo [STRING]         write string to standard output
  \i FILE                execute commands from file
  \o [FILE]              send all query results to file or |pipe
  \qecho [STRING]        write string to query output stream (see \o)

.....

postgres-# \q
$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
server starting
$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile stop
waiting for server to shut down.... done
server stopped
$

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值