centos6.5 64位系統安裝postgresql資料庫教程

來源:互聯網
上載者:User

一、安裝postgresql

yum -y install postgresql postgresql-server postgresql-devel
mkdir /work/pgdata
useradd postgres -d /work/pgdata
chown postgres.postgres -R /work/pgdata
su - postgres

vim ~/.bash_profile 添加如下內容

export PGHOME=/work/pgdata
export PGDATA=/work/pgdata/data

二、初始化並設定postgresql字元集

1、修改系統字元集為:UTF-8

vim /etc/sysconfig/i18n

LANG="en_US.UTF-8"

2、切換到postgres帳號,初始化資料庫

 

initdb -E UTF8

3、修改postgresql設定檔

/work/pgdata/data/postgresql.conf修改


listen_addresses = '*'
port = 5432
max_connections = 1000
/work/pgdata/data/pg_hba.conf 最後添加可信任網路:

1
2
host  all     all 10.0.0.1/8      trust
host  all     all 192.168.0.0/24      trust

三、啟動資料庫

/etc/init.d/postgresql start
chkconfig postgresql on
ps aux | grep postgresql
postgres 41659  0.0  0.0 216280  5840 ?  S  16:33 0:00 /usr/bin/postmaster -p 5432 -D /work/pgdata/data
postgres 41661  0.0  0.0 179292  1284 ?        Ss   16:33   0:00 postgres: logger process                       
postgres 41663  0.0  0.0 216280  1764 ?        Ss   16:33   0:00 postgres: writer process                       
postgres 41664  0.0  0.0 216280  1472 ?        Ss   16:33   0:00 postgres: wal writer process                   
postgres 41665  0.0  0.0 216548  1808 ?        Ss   16:33   0:00 postgres: autovacuum launcher process          
postgres 41666  0.0  0.0 179420  1528 ?        Ss   16:33   0:00 postgres: stats collector process              
postgres 41686  0.0  0.0 218248  5428 ?        Ss   16:35   0:00 postgres: opcode opcode 192.168.0.80(38453) idle
postgres 41832  0.0  0.0 217636  4892 ?      Ss   16:54   0:00 postgres: postgres postgres [local] idle

四、建立資料庫和對應帳號:

su - postgres

系統提示符會變為”postgres=#”,表示這時已經進入了資料庫控制台。


\password postgres;  #給postgres設定密碼

CREATE USER opcode WITH PASSWORD 'opcodepasswd';
CREATE DATABASE opcode OWNER opcode;
GRANT ALL PRIVILEGES ON DATABASE opcode to opcode;
\h:查看SQL命令的解釋,比如\h select。

\?:查看psql命令列表。\l:列出所有資料庫。

\c [database_name]:串連其他資料庫。

\d:列出當前資料庫的所有表格。

\d [table_name]:列出某一張表格的結構。

\du:列出所有使用者。

\e:開啟文字編輯器。

\conninfo:列出當前資料庫和串連的資訊。

#其他知識


createuser --superuser postgres #建立並設定管理員帳號

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.