Linux-05安装Postgres

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值