用户登录
用户注册

分享至

postgresql for linux

  • 作者: BETTER62881837
  • 来源: 51数据库
  • 2020-09-26
进入/opt/pgsql-9.1.7目录可以看到安装后的postgresql的文件。

linux下安装PostgreSQL数据库步骤如下:
0.编译环境
  • Linux: CentOS 5.5
  • gcc: 4.1.2
    1. 安装PostgreSQL
    1) 解压postgresql-9.1.7.tar.bz2
    #tar jxvf?postgresql-9.1.7.tar.bz2



    2) 进入解压后的postgresql-9.1.7目录
    #cd?postgresql-9.1.7



    3) 编译postgresql源码
    #./configure --prefix=/opt/pgsql-9.1.7
    #make



    #make install



    至此,完成postgresql的安装。进入/opt/pgsql-9.1.7目录可以看到安装后的postgresql的文件。
    #ls /opt/pgsql-9.1.7



    2.创建postgresql数据库
    1) 创建postgres用户
    #useradd postgres
    修改postgres密码
    #passwd postgres



    2) 设置postgres用户的环境变量
    切换到postgres用户
    #su - postgres



    进入postgres的主目录
    #cd ~



    编辑~/.bash_profile文件
    #vi?~/.bash_profile
    设置以下的环境变量
    export PGHOME=/opt/pgsql-9.1.7
    export PGDATA=~/data



    保存,退出vi。执行以下命令,使环境变量生效
    #source ~/.bash_profile



    3) 初始化postgres数据库
    #initdb
    至此,完成postgres数据库的初始化。
    4) 启动postgres数据库实例
    #pg_ctl start



    可以看到postgresql数据库实例已经启动,通过下面的命令可以查看系统中运行的postgres进程
    #ps -ef | grep postgres



    5) 连接postgresql数据库
    #psql -h 127.0.0.1 -d postgres -U postgres



    6) 停止postgresql数据库实例
    #pg_ctl stop
    #ps -ef | ?grep postgres



    可以看到已经没有postgres进程
    3. 设置PostgreSQL开机自启动
    PostgreSQL的开机自启动脚本位于PostgreSQL源码目录的contrib/start-scripts路径下



    linux文件即为linux系统上的启动脚本
    1)修改linux文件属性,添加X属性
    #chmod a+x linux
    2) 复制linux文件到/etc/init.d目录下,更名为postgresql
    #cp linux /etc/init.d/postgresql
    3)修改/etc/init.d/postgresql文件的两个变量
    prefix设置为postgresql的安装路径:/opt/pgsql-9.1.2
    PGDATA设置为postgresql的数据目录路径:



    4) 执行service postgresql start,就可以启动PostgreSQL服务
    #service postgresql start



    5)设置postgresql服务开机自启动
    #chkconfig --add postgresql
    执行上面的命令,就可以实现postgresql服务的开机自启动。




  •   OS:suselinux11(64bit)
    PostgreSQL:PostgreSQL9.1(64bit)
    1、建用户及目录
    linux:/home # groupadd postgres
    linux:/home # useradd postgres -g postgres
    linux:/home # mkdir /home/postgres
    linux:/home # chown postgres:postgres /home/postgres
    linux:/home # passwd postgres
    2、用root运行安装(不能以postgres运行安装)
    linux:/opt # mkdir /opt/PostgreSQL
    linux:/opt # chown postgres:postgres /opt/PostgreSQL
    linux:/opt/PostgreSQL # chmod +x postgresql-9.1.1-1-linux-x64.bin
    linux:/opt/PostgreSQL # ./postgresql-9.1.1-1-linux-x64.bin
    ----------------------------------------------------------------------------
    Welcome to the PostgreSQL Setup Wizard.
    ----------------------------------------------------------------------------
    Please specify the directory where PostgreSQL will be installed.
    Installation Directory [/opt/PostgreSQL/9.1]:
    ----------------------------------------------------------------------------
    Please select a directory under which to store your data.
    Data Directory [/opt/PostgreSQL/9.1/data]:
    ----------------------------------------------------------------------------
    Please provide a password for the database superuser (postgres). A locked Unix
    user account (postgres) will be created if not present.
    Password :
    Retype password :
    ----------------------------------------------------------------------------
    Please select the port number the server should listen on.
    Port [5432]:
    ----------------------------------------------------------------------------
    Advanced Options
    Select the locale to be used by the new database cluster.
    Locale
    [1] [Default locale]
    [2] C
    [3] POSIX
    ...
    [441] zu_ZA
    [442] zu_ZA.utf8
    Please choose an option [1] :
    ----------------------------------------------------------------------------
    Setup is now ready to begin installing PostgreSQL on your computer.
    Do you want to continue? [Y/n]: y
    ----------------------------------------------------------------------------
    Please wait while Setup installs PostgreSQL on your computer.
    Installing
    0% ______________ 50% ______________ 100%
    ########################################
    ----------------------------------------------------------------------------
    Setup has finished installing PostgreSQL on your computer.
    3、相关配置
    (1)环境变量
    postgres@campost:~> vi .profile(new file)
    export PGSQL_HOME=/opt/PostgreSQL/9.1
    export PATH=$PGSQL_HOME/bin:$PATH
    #export PGDATAS=$PGSQL_HOME/datas
    export PGDATA=$PGSQL_HOME/data
    export PGDATABASE=postgres
    export PGUSER=postgres
    #export PGPORT=1234
    export PGLOCALEDIR=$PGSQL_HOME/share/locale
    export MANPATH=$MANPATH:$PGSQL_HOME/share/man
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGSQL_HOME/lib
    postgres@campost:~> . .profile
    配置如上环境表里之后,可以使用psql连接数据库:
    postgres@campost:/opt/PostgreSQL/9.1/data> psql
    Password:
    psql.bin (9.1.1)
    Type "help" for help.
    postgres=# help
    You are using psql, the command-line interface to PostgreSQL.
    Type: \copyright for distribution terms
    \h for help with SQL commands
    \? for help with psql commands
    \g or terminate with semicolon to execute query
    \q to quit
    postgres=#
    (2)网络配置
    加网络信任关系:
    ----详细信息请参考PostgreSQL document,20.1. pg_hba.conf 文件
    vi /opt/PostgreSQL/9.1/data/pg_hba.conf
    添加一行:host all all trust
    重启数据库:
    postgres@campost:~> pg_ctl restart
    waiting for server to shut down.... done
    server stopped
    server starting
    此时可以用PgAdmin远程登录postgres用户了,此时只有一个库postgres。
    软件
    前端设计
    程序设计
    Java相关