`
LJ你是唯一LT
  • 浏览: 238866 次
社区版块
存档分类
最新评论

安装postgresql 9.1.1

阅读更多
安装postgresql 9.1.1 ---版本自选,步骤相同

1、安装必要的依赖包
yum install -y gcc readline readline-devel zlib zlib-devel iostat python python-devel

2、解压
[postgres@mysqltest tmp]$ tar -zxvf postgresql-9.1.1.tar.gz 
[postgres@mysqltest tmp]$ cd postgresql-9.1.1
[root@localhost postgresql-9.1.1]# ll
total 2144
-rw-r--r--  1 258 258     385 Sep 22  2011 aclocal.m4
drwxrwxrwx  2 258 258    4096 Jul 16 00:14 config
-rwxr-xr-x  1 258 258  862411 Sep 22  2011 configure
-rw-r--r--  1 258 258   63014 Sep 22  2011 configure.in
drwxrwxrwx 51 258 258    4096 Jul 16 00:14 contrib
-rw-r--r--  1 258 258    1192 Sep 22  2011 COPYRIGHT
drwxrwxrwx  3 258 258    4096 Jul 16 00:14 doc
-rw-r--r--  1 258 258    3741 Sep 22  2011 GNUmakefile.in
-rw-r--r--  1 258 258 1077847 Sep 22  2011 HISTORY
-rw-r--r--  1 258 258   76550 Sep 22  2011 INSTALL
-rw-r--r--  1 258 258    1489 Sep 22  2011 Makefile
-rw-r--r--  1 258 258    1284 Sep 22  2011 README
drwxrwxrwx 14 258 258    4096 Jul 16 00:14 src
[root@localhost postgresql-9.1.1]#

3、编译安装
使用默认,那么会安装到/usr/local/pgsql/bin目录下
./configure --prefix=/home/pgsql/9.1/   指定目录

安装:
gmake命令   ---直接执行,大概3-5分钟,最后几行如下:
gmake[2]: Leaving directory `/postgresql-9.1.1/src/test/regress'
gmake[1]: Leaving directory `/postgresql-9.1.1/src'
gmake -C config all
gmake[1]: Entering directory `/postgresql-9.1.1/config'
gmake[1]: Nothing to be done for `all'.
gmake[1]: Leaving directory `/postgresql-9.1.1/config'
All of PostgreSQL successfully made. Ready to install.

gmake install
最后两行:
gmake[1]: Leaving directory `/postgresql-9.1.1/config'
PostgreSQL installation complete.

也可以直接使用make && make install

5、新建数据库用户postgres
cd /home/pgsql/9.1
mkdir data
useradd postgres
passwd postgres
cd /home
chown -R postgres:postgres  pgsql/   --修改data目录的属主为postgres,以便它可以进行读写


6、环境变量设置,这一步千万不要忘记
vi ~/.bash_profile
export PGDATA=/home/pgsql/9.1/data
export LD_LIBRARY_PATH=/home/pgsql/9.1/lib
export PATH=/home/pgsql/9.1/bin:$PATH
编辑完之后,记得source .bash_profile

7、数据库初始化
initdb 禁止除 PostgreSQL 用户帐户以外的任何用户访问这个目录。
[postgres@localhost pg]$ /home/pgsql/9.1/bin/initdb  -D /home/pgsql/9.1/data


8、启动和停止命令:
启动:
安装路径/bin/pg_ctl -D /usr/local/pgsql/data start
安装路径/bin/postmaster -D /home/pgsql/9.1/data > logfile 2>&1 &
 
停止:
安装路径/bin/pg_ctl -D /usr/local/pgsql/data stop

关闭:-m 是模式 smart 是等连接全部停掉。 fast 事务提交与回滚当前事务后关机 immediate 相当于断电
/usr/pgsql/bin/pg_ctl stop -D /usr/pgsql/data -m f

启动:
/usr/pgsql/bin/postgres -D /usr/pgsql/data
/usr/pgsql/bin/pg_ctl restart -D /usr/pgsql/data -m f
/usr/pgsql/bin/pg_ctl start -D /usr/pgsql/data -m f

9、修改远程连接设置
修改文件 /opt/sda/pg922/data/postgresql.conf
#listen_addresses = 'local' 改为 : listen_addresses = '*'

修改文件 /opt/sda/pg922/data/pg_hba.conf 安装下面的形式改
# IPv4 local connections:
host    all             all             0.0.0.0/0            md5

10、参数设置
可参考12.20上的设置:(注意12.20的内存是32GB)
[root@pg data]# grep ^[a-z] postgresql.conf
listen_addresses = '*' # what IP address(es) to listen on;
port = 5432 # (change requires restart)
max_connections = 500 # (change requires restart)
superuser_reserved_connections = 3 # (change requires restart)
shared_buffers = 8GB # min 128kB
work_mem = 400MB # min 64kB
maintenance_work_mem = 512MB # min 1MB
wal_level = hot_standby # minimal, archive, or hot_standby
fsync = on # turns forced synchronization on or off
synchronous_commit = on # synchronization level; on, off, or local
checkpoint_segments = 128 # in logfile segments, min 1, 16MB each
checkpoint_timeout = 20min # range 30s-1h
archive_mode = on # allows archiving to be done
archive_command = 'cp %p /home/pgsql/backup_new/archived_log/%f' # command to use to archive a logfile segment
max_wal_senders = 5 # max number of walsender processes
wal_keep_segments = 1024 # in logfile segments, 16MB each; 0 disables
vacuum_defer_cleanup_age = 4 # number of xacts by which cleanup is delayed
replication_timeout = 120s # in milliseconds; 0 disables
max_standby_archive_delay = 60min # max delay before canceling queries
max_standby_streaming_delay = 60min # max delay before canceling queries
effective_cache_size = 30GB
logging_collector = on # Enable capturing of stderr and csvlog
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern,
log_truncate_on_rotation = off # If on, an existing log file with the
log_rotation_age = 1d # Automatic rotation of logfiles will
log_rotation_size = 10MB # Automatic rotation of logfiles will
log_min_duration_statement = 500ms # -1 is disabled, 0 logs all statements
log_line_prefix = '%t-%d-%h-%a :' # special values:
log_statement = 'ddl' # none, ddl, mod, all
log_temp_files = 10MB # log temporary files equal or larger
datestyle = 'iso, ymd'
lc_messages = 'en_US.UTF-8' # locale for system error message
lc_monetary = 'en_US.UTF-8' # locale for monetary formatting
lc_numeric = 'en_US.UTF-8' # locale for number formatting
lc_time = 'en_US.UTF-8' # locale for time formatting
default_text_search_config = 'pg_catalog.english'

11、新建归档存放目录
su - postgres
cd /home/pgsql/
mkdir -p backup_new/archived_log


12、添加postgresql到自动启动,以便可以service postgresql start启动
添加自动启动
[root@mysqltest data]# vi /etc/init.d/postgresql   ---将自动启动的代码贴进去
#! /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

# Installation prefix
prefix=/home/pgsql/9.1

# Data directory
PGDATA="/home/pgsql/9.1/data"

# Who to run the postmaster as, usually "postgres".  (NOT "root")
PGUSER=postgres

# Where to keep a log file
PGLOG="$PGDATA/serverlog"

# The path that is to be used for the script
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# What to use to start up the postmaster.  (If you want the script to wait
# until the server has started, you could use "pg_ctl start -w" here.
# But without -w, pg_ctl adds no value.)
DAEMON="$prefix/bin/postmaster"

# What to use to shut down the postmaster
PGCTL="$prefix/bin/pg_ctl"

set -e

# Only start if we can find the postmaster.
test -x $DAEMON ||
{
echo "$DAEMON not found"
if [ "$1" = "stop" ]
then exit 0
else exit 5
fi
}


# Parse command line parameters.
case $1 in
  start)
echo -n "Starting PostgreSQL: "
test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
echo "ok"
;;
  stop)
echo -n "Stopping PostgreSQL: "
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast"
echo "ok"
;;
  restart)
echo -n "Restarting PostgreSQL: "
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
echo "ok"
;;
  reload)
        echo -n "Reload PostgreSQL: "
        su - $PGUSER -c "$PGCTL reload -D '$PGDATA' -s"
        echo "ok"
        ;;
  status)
su - $PGUSER -c "$PGCTL status -D '$PGDATA'"
;;
  *)
# Print help
echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2
exit 1
;;
esac

exit 0

[root@mysqltest init.d]# chmod +x postgresql
[root@mysqltest init.d]# chkconfig --add postgresql

以服务的形式启动pg
[root@mysqltest init.d]# service postgresql start
Starting PostgreSQL: ok

13、创建用户,修改postgres密码:
postgres=# CREATE ROLE engine LOGIN ENCRYPTED PASSWORD 'enginepassword'  NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;

CREATE ROLE fenxi LOGIN
  ENCRYPTED PASSWORD 'fenxi'
  NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;

CREATE ROLE sqluser LOGIN
  ENCRYPTED PASSWORD 'sqlpassword'
  NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
 
CREATE ROLE repluser LOGIN
  ENCRYPTED PASSWORD 'repluser'
  SUPERUSER INHERIT NOCREATEDB NOCREATEROLE REPLICATION;

postgres=# alter user postgres password with 'tina';


14、建库:
CREATE DATABASE rename_check
WITH OWNER = postgres
   ENCODING = 'UTF8'
   TABLESPACE = pg_default
   LC_COLLATE = 'zh_CN.UTF-8'
   LC_CTYPE = 'zh_CN.UTF-8'
   CONNECTION LIMIT = -1
   TEMPLATE template0;    --必须是这个模板,不然会报下面的错

GRANT CONNECT, TEMPORARY ON DATABASE rename_check TO public;
GRANT ALL ON DATABASE rename_check TO postgres;
COMMENT ON DATABASE rename_check  IS '改名系统';

报错:
ERROR:  new collation (zh_CN.UTF-8) is incompatible with the collation of the template database (en_US.UTF-8)

15、备份表(12.20):
pg_dump --host localhost --port 5432 --username postgres -Fc --encoding=UTF8 --verbose
--file /opt/db_backup/tmp_bk/five_tables.bk  -t t_rename_sample_state_list  -t t_rename_sample_state_sts
-t  t_rename_task_type -t t_rename_task_type_list -t  t_rename_task_type_sts tm_samples

16、新库来恢复表(12.108):
pg_restore -U postgres -d rename_check  /tmp_bk/t_analyst_list.bk  2>&1
pg_restore -U postgres -d rename_check  /tmp_bk/t_rename_analyst_list.bk 2>&1


分享到:
评论

相关推荐

    postgreSQL9.1.1英文帮助文件

    postgreSQL9.1.1英文帮助文件chm格式的。

    postgresql-9.1.1-1-windows-binaries

    postgresql-9.1.1-1-windows-binaries

    postgresql-9.1.1.tar.gz

    postgresql安装文件

    Devart UniDAC 9.1.1 Professional For RAD Studio 11 Alexandria

    主要组件有ODAC(Oracle数据访问组件),SDAC(SQL Server数据访问组件),MyDAC(MySQL数据访问)包括IBDAC组件(InterBase 和 Firebird 数据访问组件)、PgDAC 组件(PostgreSQL 数据访问组件)和 LiteDAC 组件...

    Devart UniDAC 9.1.1 Professional For RAD Studio 10.3 Rio

    主要组件有ODAC(Oracle数据访问组件),SDAC(SQL Server数据访问组件),MyDAC(MySQL数据访问)包括IBDAC组件(InterBase 和 Firebird 数据访问组件)、PgDAC 组件(PostgreSQL 数据访问组件)和 LiteDAC 组件...

    unidac_9.1.1_D11.rar

    主要组件有ODAC(Oracle数据访问组件),SDAC(SQL Server数据访问组件),MyDAC(MySQL数据访问)包括IBDAC组件(InterBase 和 Firebird 数据访问组件)、PgDAC 组件(PostgreSQL 数据访问组件)和 LiteDAC 组件...

    Devart UniDAC 9.1.1 Professional For RAD Studio 10.4 Sydney

    主要组件有ODAC(Oracle数据访问组件),SDAC(SQL Server数据访问组件),MyDAC(MySQL数据访问)包括IBDAC组件(InterBase 和 Firebird 数据访问组件)、PgDAC 组件(PostgreSQL 数据访问组件)和 LiteDAC 组件...

    UniDAC 9.1.1 Pro

    主要组件有ODAC(Oracle数据访问组件),SDAC(SQL Server数据访问组件),MyDAC(MySQL数据访问)包括IBDAC组件(InterBase 和 Firebird 数据访问组件)、PgDAC 组件(PostgreSQL 数据访问组件)和 LiteDAC 组件...

    php网络开发完全手册

    9.1.1 语法错误 136 9.1.2 语义错误 137 9.1.3 逻辑错误 137 9.1.4 注释错误 137 9.1.5 运行时的错误 138 9.2 PHP程序调试策略 138 9.2.1 PHP的错误级别 138 9.2.2 打开PHP的错误报告 140 9.2.3 使用print进行程序...

    MySQL中文参考手册

    + 4.10.2 在 Win32上安装 ActiveState Perl + 4.10.3 在 Win32 上安装 MySQL Perl 分发 + 4.10.4 使用 Perl DBI/DBD接口遇到的问题 o 4.11 系统特定的问题 + 4.11.1 Solaris注意事项 + 4.11.2 Solaris 2.7 ...

    MYSQL

    9.1.1 用于数据和排序的字符集 9.1.2 增加一个新的字符集 9.1.3 多字节字符支持 9.2 更新日志 9.3 MySQL数据库表可以有多大? 9.4 MySQL数据库表类型 10 从 MySQL 得到最大的性能 ...

    MySQL中文参考手册.chm

    9.1.1 用于数据和排序的字符集 9.1.2 增加一个新的字符集 9.1.3 多字节字符支持 9.2 更新日志 9.3 MySQL数据库表可以有多大? 9.4 MySQL数据库表类型 10 从 MySQL 得到最大的...

    SQL必知必会(第3版)--详细书签版

    9.1.1 AVG()函数 52 9.1.2 COUNT()函数 53 9.1.3 MAX()函数 54 9.1.4 MIN()函数 54 9.1.5 SUM()函数 55 9.2 聚集不同值 56 9.3 组合聚集函数 57 9.4 小结 58 第10章 分组数据 59 10.1 数据分组 59 10.2 ...

    Spring Security 中文教程.pdf

    9.1.1. 配置 9.2. DigestAuthenticationFilter 9.2.1. Configuration 10. Remember-Me认证 10.1. 概述 10.2. 简单基于散列标记的方法 10.3. 持久化标记方法 10.4. Remember-Me接口和实现 10.4.1. ...

    SpringSecurity 3.0.1.RELEASE.CHM

    9.1.1. 配置 9.2. DigestAuthenticationFilter 9.2.1. Configuration 10. Remember-Me认证 10.1. 概述 10.2. 简单基于散列标记的方法 10.3. 持久化标记方法 10.4. Remember-Me接口和实现 10.4.1. ...

    Spring Security-3.0.1中文官方文档(翻译版)

    9.1.1. 配置 9.2. DigestAuthenticationFilter 9.2.1. Configuration 10. Remember-Me 认证 10.1. 概述 10.2. 简单基于散列标记的方法 10.3. 持久化标记方法 10.4. Remember-Me 接口和实现 10.4.1. ...

    SQL必知必会(第3版-PDF清晰版)part1

    9.1.1 AVG()函数..... 52 9.1.2 COUNT()函数..... 53 9.1.3 MAX()函数..... 54 9.1.4 MIN()函数..... 54 9.1.5 SUM()函数..... 55 9.2 聚集不同值..... 56 9.3 组合聚集函数..... 57 9.4 小结..... 58 第10章 分组...

Global site tag (gtag.js) - Google Analytics