postgresql安装

默北 数据库postgresql安装已关闭评论5,906字数 1913阅读6分22秒阅读模式
  1. # yum install readline-devel
    未安装readline-devel会出现readline library not found错误
    # wget http://ftp.postgresql.org/pub/source/v9.1.2/postgresql-9.1.2.tar.bz2
    # tar jxvf postgresql-9.1.2.tar.bz2 -C ../software/
    # ./configure --prefix=/home/xuhh/pgsql912  --with-perl --with-python
    # gmake
    # gmake install
    # mkdir /home/xuhh/pgsql912/data
    # adduser postgres
    # chown -R postgres.postgres /home/xuhh/pgsql912
    # chown postgres.postgres /home/xuhh/pgsql912/data
    # su - postgres
    $ /home/xuhh/pgsql912/bin/initdb -D /home/xuhh/pgsql912/data  //初始化数据
    $ /home/xuhh/pgsql912/bin/postgres -D /home/xuhh/pgsql912/data > /tmp/pg-logfile 2>&1 &  //启动数据库
  2. $ /home/xuhh/pgsql912/bin/createdb test  //创建数据库
    $ /home/xuhh/pgsql912/bin/psql -d test //连接数据库
    test=# CREATE TABLE  test (id serial, name varchar(32));
    test=# insert into test values(1,'abc');
    test=# insert into test values('2','bbb');
    test=# \dp+   //查看表空间
    Access privileges
    Schema |    Name     |   Type   | Access privileges | Column access privileges
    --------+-------------+----------+-------------------+--------------------------
    public | test        | table    |                   |
    public | test_id_seq | sequence |                   |
    (2 rows)
    test=# \dt+   //查看表
    List of relations
    Schema | Name | Type  |  Owner   |    Size    | Description
    --------+------+-------+----------+------------+-------------
    public | test | table | postgres | 8192 bytes |
    (1 row)
  3. test=# create tablespace xxoo location '/tmp/';    //创建表空间
  4. test=# select * from pg_tablespace;    //查看表空间
    spcname   | spcowner | spclocation | spcacl | spcoptions
    ------------+----------+-------------+--------+------------
    pg_default |       10 |             |        |
    pg_global  |       10 |             |        |
    xxoo       |       10 | /tmp/xxoo   |        |
    (3 rows)
  5. test=# alter tablespace xxoo rename to ttlsa;   //更改表空间名
    ALTER TABLESPACE
    test=# select * from pg_tablespace;
    spcname   | spcowner | spclocation | spcacl | spcoptions
    ------------+----------+-------------+--------+------------
    pg_default |       10 |             |        |
    pg_global  |       10 |             |        |
    ttlsa      |       10 | /tmp/xxoo   |        |
    (3 rows)
文章源自运维生存时间-https://www.ttlsa.com/database/install-postgresql-on-linux/
weinxin
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
默北
  • 本文由 发表于 11/01/2012 16:38:08
  • 转载请务必保留本文链接:https://www.ttlsa.com/database/install-postgresql-on-linux/