Linux系统中PostgreSql下载及安装基本知识


Linux系统中PostgreSql下载及安装基本知识学习:

【ユーザー追加
[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

相关内容