linux下PostgreSql下载和安装(初学)

本文档详细介绍了在Linux CentOS系统中安装PostgreSQL数据库的过程,包括用户创建、下载安装包、启动数据库、设置自动启动,以及创建、查询、删除数据库和表的操作。适合PostgreSQL初学者参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >





【ユーザー追加

[root@localhost ~]# useradd postgres
[root@localhost ~]# passwd postgres

PostgreSQLダウンロード】
[root@localhost ~]# cd /usr/local/src
[root@localhost ~]# wget ftp://ftp.postgresql.org/pub/binary/v8.0.15/linux/rpms/redhat/rhel3.0/postgresql-server-8.0.15-1PGDG.i386.rpm
[root@localhost ~]# wget ftp://ftp.postgresql.org/pub/binary/v8.0.15/linux/rpms/redhat/rhel3.0/postgresql-devel-8.0.15-1PGDG.i386.rpm
[root@localhost ~]# wget ftp://ftp.postgresql.org/pub/binary/v8.0.15/linux/rpms/redhat/rhel3.0/postgresql-libs-8.0.15-1PGDG.i386.rpm
[root@localhost ~]# wget ftp://ftp.postgresql.org/pub/binary/v8.0.15/linux/rpms/redhat/rhel3.0/postgresql-8.0.15-1PGDG.i386.rpm

PostgreSQLインストール
[root@localhost ~]# rpm -ivh postgresql-*8.0.15-1PGDG.i386.rpm

PostgreSQL起動
[root@localhost ~]# /etc/rc.d/init.d/postgresql start                         

PostgreSQL自動起動設定
[root@localhost ~]# chkconfig postgresql on                                   
PostgreSQL自動起動設定確認】
[root@localhost ~]# chkconfig --list postgresql                           
    postgresql 0:off 1:off 2:on 3:on 4:on 5:on 6:off                  ランレベル2~5のonを確認

【postgresユーザになる】
[root@
localhost ~]# su - postgres

【PostgreSQLにcentosユーザを追加(システムに登録済のユーザであること)】

-bash-2.05b$ createuser -AdPE centos
    CREATE USER

【データベースtestを作成】
-bash-2.05b$ createdb --encoding EUC_JP test
    CREATE DATABASE

【データベースtestdbを作成確認】
-bash-2.05b$ psql -l
             List of databases
       Name    |   Owner   | Encoding
    -----------+-----------+-----------
     template0 | postgres  | SQL_ASCII
     template1 | postgres  | SQL_ASCII
     test      | centos    | EUC_JP
    (3 rows)


【psqlツール起動】
-bash-2.05b$ psql test

【テーブルtestを作成】
-bash-2.05b$ create table test(num int, name varchar(50));
    CREATE TABLE
    test=> /d test ← テーブルtest作成確認
                Table "public.test"
     Column |         Type          | Modifiers
    --------+-----------------------+-----------
     num    | integer               |
     name   | character varying(50) |

【データ登録】
 test=> insert into test values(1,'山田太郎'); ← テーブルtestにデータを登録
    INSERT

【データ照会】
test=> select * from test;
         num |   name
         -----+-----------
        1 | 山田太郎
      (1 row)

【テーブル削除】
 test=> drop table test;
    DROP TABLE

【psqlツール停止】
 test=> /q

【データベース削除】
-bash-2.05b$ dropdb test
    DROP DATABASE
-bash-2.05b$ exit

【PostgreSQLユーザ削除】
[root@linux ~]# su - postgres
-bash-2
.05b$ dropuser centos
    DROP USER
-bash-2
.05b$ exit


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值