顯示具有 PostgreSQL 標籤的文章。 顯示所有文章
顯示具有 PostgreSQL 標籤的文章。 顯示所有文章

2008年9月12日 星期五

PG 在 YUM 後的出錯處理

    

CentOS 5.0 下以 yum 安裝 PostgreSQL 8.3 記錄中,未提及出錯的處理,現在補回。


錯誤處理訊息


YUM 後跑 service postdgresql start 出現以下錯誤訊息:

    An old version of the database format was found.
    You need to upgrade the data format before using PostgreSQL.
    See /usr/share/doc/postgresql-8.3.3/README.rpm-dist for more information.

趴文後,知道是前(8.1)後(8.3)資料庫格式不符。
唯一辦法是重設整個 pg 系統,須執行以下工序處理:

1- 清空 pg 的設定資料。

    rm -rf /var/lib/pgsql/data
        或
    cd /var/lib/pgsql/data
    rm -rf *

    用第一個方法偶然出大錯,
第二方案未試出錯

2- 進入 pgsql 系統

    [root@centos001 data]# su postgresql
    bash-3.2$

3- 重設 pg 系統
    initdb -d /var/lib/pgsql/data
    
    
萬事 OK .................    
    
    
    


2008年9月9日 星期二

修改 postgres 的密碼 (三)


修改 postgres 的密碼 (三)


參考自:如何將 PostgreSQL 開放透過網路連線操作 ?
 



    第十九章 資料庫系統



1- login 入 PostgreSQL

  [root@c52 ~]# su -l postgres

  -bash-3.2$ psql template1;

     Welcome to psql 8.1.11, the PostgreSQL interactive terminal.
      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


2- 以 ALTER USER 指令改密碼,然後離開。

   template1=# ALTER USER postgres WITH PASSWORD '789789';
   ALTER ROLE
   template1=# quit


3- 測試

   [root@c52 ~]# su postgres
   bash-3.2$ psql -l
        could not change directory to "/root"
         List of databases
         Name | Owner | Encoding
        -----------+----------+----------
         postgres | postgres | UTF8
         template0 | postgres | UTF8
         template1 | postgres | UTF8
        (3 rows)

        bash-3.2$
        
        
        

2008年8月27日 星期三

修改 postgres 的密碼 (二)

修改 postgres 的密碼 (二)

為了 postgres 的空白密碼,搞了兩天。

今天發現另一個改密碼的辦法。

1- 安裝 CentOS 5.2 後啟動 PostgreSQL。

  service postgresql start
  
  它們自動跑 initdb -D /var/lib/pgsql/data
  
2- 修改 pg_hba.conf

  vi /var/lib/pgsql/data/pg_hba.conf

  在 # IPv4 local connections: 加入一行
  host all all 192.168.0.1/24 trust

3- 然後用 pgAdmin III 連入 PostgreSQL,「儲存密碼」欄要選。

4- 在 pgAdmin 內更改密碼。



5- 重新修改 pg_hba.conf 如下:

  # TYPE DATABASE USER CIDR-ADDRESS METHOD
  # "local" is for Unix domain socket connections only
  local all all ident sameuser

  # IPv4 local connections:
  host all all 127.0.0.1/32 ident sameuser
  host all all 192.168.0.1/24 password
  #host all all 192.168.0.1/24 trust

  # IPv6 local connections:
  host all all ::1/128 ident sameuser

6- 重新啟動 PostgreSQL。

  service postgresql start

7- 再以 pgAdmin 登入時,要輸入密碼了。

打不開 PostgreSQL 預設的 port 5432 ?

打不開 PostgreSQL 預設的 port 5432 ?

1- 第一次 PgAdmin 連入時,出了下面的警告。

2- 簡單來看,是未有打開 PostgreSQL 預設的 port。

3- 這可以用 iptables 指令加入。我比較懶,用了

  system-config-securitylevel

4- 出了操作畫面後,按 Customize 。

5- 在新畫面的最後一欄填入 5432 後按 OK。


6- 退出後,系統會自動重啟 iptables。
  
  
  

2008年8月25日 星期一

PostgreSQL 8.3 中 創建資料庫集群

PostgreSQL 8.3 中 創建資料庫集群

手冊是這樣寫的,()內是我的說明。

用檔系統的術語來說,一個資料庫集群是一個目錄,所有資料都將存放在這個目錄中。
我們把它稱做資料目錄或資料區。

在哪里存放資料完全取決於你的選擇,我們沒有缺省值,儘管 /usr/local/pgsql/data
或 /var/lib/pgsql/data 這樣的目錄很常用。

(即是由 initdb -D 來決定 data 的位置,集群可視為「資料庫」內有很多的「表」)
(/var/lib/pgsql/data 是預設的目錄,沒事不要改。)

要初始化一個資料庫集群,可以使用 initdb 命令,這個命令與 PostgreSQL 一起安裝。
你可以用 -D 選項指定資料目錄的位置,例如:

$ initdb -D /usr/local/pgsql/data

你必須以 PostgreSQL 用戶的身份來執行這條命令,這一點我們在前面一節描述過。

【提示】作為 -D 選項的替代品,你還可以使用 PGDATA 環境變數。

如果你聲明的路徑還不存在,initdb 將試圖創建它。如果你按照我們的建議創建了一個非特權
帳戶的話,你很有可能缺少做這些事情的許可權。這時,你可以自己創建該目錄(以 root 身份)
然後把該目錄的所有權交給 PostgreSQL 用戶或者賦與它寫許可權。

下面是可能有效的方法:
root# mkdir /usr/local/pgsql/data
root# chown postgres /usr/local/pgsql/data
root# su postgres
postgres$ initdb -D /usr/local/pgsql/data

如果資料目錄看起來像已經初始化過了,那麼 initdb 會拒絕運行。

因為資料目錄包含所有存儲在資料庫裏的資料,所以出於安全考慮,這個目錄不能給任何非授權用戶訪問。
因此,initdb 禁止除 PostgreSQL 用戶帳戶以外的任何用戶訪問這個目錄。

不過,因為目錄的內容是安全的,所以缺省的用戶端認證設置允許任意本地用戶連接到資料庫甚至成為超級用戶。

如果你不信任本地用戶,我們建議你使用 initdb 的 -W, --pwprompt 或 --pwfile 選項給超級用戶賦予一個口令。

還有,聲明 -A md5 或 -A password ,這樣就不會使用缺省的 trust 身份認證。或者在執行 initdb 之後,第一次
啟動伺服器之前修改 pg_hba.conf 文件。另外一些合理的方法包括 ident 認證或者用檔系統許可權禁止連接。

PostgreSQL 8.3 中增加 user 及 db

PostgreSQL 8.3 中增加 user 及 db

參考自 澎湖人No1自由、免費軟體交流網


1. 建立使用者 storylai
  # su postgres
   bash-3.00$ createuser storylai -P (-P加上密碼)
   Enter password for new user:
   Enter it again:
   Shall the new user be allowed to create databases? (y/n) n
   (建議一般使用者選 n,如是管理人則選 y )
   Shall the new user be allowed to create more new users? (y/n) n
   (建議都選 n ,除非程式需要)
   CREATE USER

2. 移除使用者 storylai
   # su postgres
    bash-3.00$ dropuser storylai
    DROP USER

3. 建立資料庫 mydb
   # su postgres
    bash-3.00$ createdb mydb
    CREATE DATABASE

4. 移除資料庫 mydb
   # su postgres
    bash-3.00$ dropdb mydb
  
  

PostgreSQL 8.3 中設定 postgres 的密碼

PostgreSQL 8.3 中設定 postgres 的密碼

參考自 澎湖人No1自由、免費軟體交流網

1. 啟動 postgresql
  # service postgresql restart

2. 以 postgres 進入 PostgreSQL
  # su postgres

3. 鍵入 psql -d postgres
  bash-3.00$ psql -d postgres
  密碼:
  ( 上面的 postgres 是指一個 DB,例如 mydb )

補充:
1. 安裝好的 pg ,postgres 是沒有密碼的。
2. pg 假設 local 下是安全,但 pgAdmin III 就連不入去。
3. 當 postgres 設好密碼後,便可增加 user 了。
  
  
  

CentOS 5.0 中 PostgreSQL 8.3 的設定檔

CentOS 5.0 中 PostgreSQL 8.3 的設定檔

1. 修改 pg_hba.conf 設定檔
   
   # vim /var/lib/pgsql/data /pg_hba.conf

   # IPv4 local connections:
     host all all 127.0.0.1/32 ident sameuser
     host all all 192.168.0.1/24  password (純文字密碼,容易截聽)
     host all all 192.168.0.1/24  md5    (加密密碼,首選)


(記得先 cp 一個 bak,改時只加以#,vim用 yy 複製,p 貼上。)
(/var/lib/pgsql/data 是預設的目錄,沒事不要改。)

2. 修改 postgresql.conf 設定檔

    # vim /var/lib/pgsql/data /postgresql.conf
    
     # listen_addresses = 'localhost'
     listen_addresses = '*'
     port = 5432    (去掉前面的 # )

3.  以 ip (192.168.0.X )連入時要留意 iptables 的設定。

CentOS 5.0 下以 yum 安裝 PostgreSQL 8.3

CentOS 5.0 下以 yum 安裝 PostgreSQL 8.3

當然可以用 tar 包來安裝,但 yum 簡單些。

參考自 http://onezstudio.blogspot.com/

1. 導入PostgreSQL YUM Repository的rpm
  # wget http://yum.pgsqlrpms.org/reporpms/8.3/pgdg-centos-8.3-4.noarch.rpm
  # rpm -ivh pgdg-centos-8.3-4.noarch.rpm

2. 升級PostgreSQL
  # yum update

3. 啟動 postgresql
   # service postgresql start
   初始化資料庫: [ 確定 ]
   啟動 postgresql 服務: [ 確定 ]