Linux-05安装Postgres

来源:互联网 发布:网络共享打不开 编辑:程序博客网 时间:2024/06/06 17:46

1 准备工作

系统:CentOS 5.7软件:postgressql-9.2.21-1-linux-x64.run

2 安装Postgresql

2.1 下载安装包地址:

    https://www.enterprisedb.com/downloads/postgres-postgresql-downloads

2.2 上传软件至/var/lib上

[root@db1 lib]# ls    alternatives  dovecot           mlocate                            random-seed   stateless    bluetooth     games             multipath                          rhsm          tpm    dav           hal               news                               rpm           webalizer    dbus          iscsi             nfs                                scrollkeeper  yum    dhclient      logrotate.status  php                                sepolgen    dhcpv6        misc              postgresql-9.2.21-1-linux-x64.run  spamassassin

2.3 授予该安装文件有执行权限

    [root@db1 lib]# chmod 755 postgresql-9.2.21-1-linux-x64.run 

2.4 安装数据库

2.4.1 执行安装程序

    [root@db1 lib]# ./postgresql-9.2.21-1-linux-x64.run 

2.4.2 设置数据库安装目录

    Please specify the directory where PostgreSQL will be installed.    Installation Directory [/var/lib/pgd]: /var/lib/pgsql/

2.4.3 设置数据库保存路径

    Please select a directory under which to store your data.    Data Directory [/var/lib/pgsql/data]: /var/lib/pgsql/9.2/data

2.4.4 设置postgres账户密码

        记住,之后需要使用

2.4.5 设置数据库的编码格式

        选择zh_CN.utf8

2.4.6 验证

    执行命令ps -e | grep postgres,查看进程是否存在。    [root@db1 lib]# ps -e | grep postgres     5014 ?        00:00:00 postgres     5019 ?        00:00:00 postgres     5021 ?        00:00:00 postgres     5022 ?        00:00:00 postgres     5023 ?        00:00:00 postgres     5024 ?        00:00:00 postgres     5025 ?        00:00:00 postgres    执行命令lsof -i:5432,查看数据库端口是否启用。 [root@db1 lib]# lsof -i :5432    COMMAND   PID     USER   FD   TYPE DEVICE SIZE NODE NAME    postgres 5014 postgres    6u  IPv4  37355       TCP *:postgres (LISTEN)

2.4.7 初始化数据库

    使用postges用户进行初始化,但是报权限不够    bash-3.2$ ./initdb  -D /var/lib/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 "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".    creating directory /var/lib/data ... initdb: could not create directory "/var/lib/data": 权限不够    将/var/lib/pgsql的拥有者该为postgres,再执行    [root@db1 lib]# chown postgres /var/lib/pgsql/    bash-3.2$ pwd    /var/lib/pgsql/bin    bash-3.2$ ./initdb -D /var/lib/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 "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".    creating directory /var/lib/pgsql/data ... ok    creating subdirectories ... ok    selecting default max_connections ... 100    selecting default shared_buffers ... 32MB    creating configuration files ... ok    creating template1 database in /var/lib/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 option -A, or    --auth-local and --auth-host, the next time you run initdb.    Success. You can now start the database server using:        ./postgres -D /var/lib/pgsql/data    or        ./pg_ctl -D /var/lib/pgsql/data -l logfile start

2.4.8 进入数据库

    bash-3.2$ ./psql    Password:     psql.bin (9.2.21)    Type "help" for help.    No entry for terminal type "xterm";    using dumb terminal settings.    postgres=#  

2.4.9 增加环境变量

    export PGHOME=/var/lib/pgsql/9.2    export PGDATA=$PGHOME/data    PATH=$PATH:$HOME/bin:$PGHOME/bin
原创粉丝点击