2014-11-08 50 views
0

我使用Vagrant + Ansible調配Ubuntu虛擬機。 Postgres安裝正確,但在每臺計算機上重新啓動並重新加載目錄/ var/run/postgresql丟失,並且postgresql服務無法啓動。爲了讓postgres運行,我需要創建unix套接字目錄並手動啓動服務。Postgres unix套接字目錄不存在

如果我嘗試和沒有插座目錄我碰到下面的錯誤

Error: Cannot stat /var/run/postgresql 
* No PostgreSQL clusters exist; see "man pg_createcluster" 

我怎樣才能解決這個讓啓動該服務?

編輯

這裏是我的PostgreSQL劇本說明

--- 
- name: Install Postgres + PostGIS 
    apt: pkg={{ item }} state=installed update_cache=yes 
    with_items: 
    - libgeos-dev 
    - postgresql-9.3 
    - postgresql-contrib-9.3 
    - postgresql-client-9.3 
    - postgresql-server-dev-9.3 
    - postgresql-9.3-postgis-2.1 
    - postgresql-9.3-postgis-2.1-scripts 
    sudo: yes 
    notify: 
    - restart postgresql 

- name: PostgreSQL on statup 
    service: name=postgresql enabled=yes state=started 
    sudo: yes 
    notify: 
    - restart postgresql 

- name: Install PostgreSQL config file 
    sudo: yes 
    template: src=postgresql.conf 
      dest=/etc/postgresql/9.3/main/postgresql.conf 
      owner={{ postgresql.user }} 
      group={{ postgresql.group }} 
    notify: 
    - restart postgresql 

- name: Install PostgreSQL Host-Based-Authentication file 
    template: src=pg_hba.conf.j2 
      dest=/etc/postgresql/9.3/main/pg_hba.conf 
      owner={{ postgresql.user }} group={{ postgresql.group }} 
    notify: restart postgresql 
    sudo: yes 
+0

你是如何安裝Postgres的?請包括該配方。 – tedder42 2014-11-08 20:26:14

回答

0

/var/run/postgresql是不應該在重啓後繼續存在。無論如何,/var/run通常在臨時文件系統中鏈接。

被Ubuntu作爲打包的PostgreSQL啓動序列是由這個函數來完成,在/usr/share/postgresql-common/init.d-functions

# start all clusters of version $1 
# output according to Debian Policy for init scripts 
start() { 
    # create socket directory 
    if [ -d /var/run/postgresql ]; then 
     chmod 2775 /var/run/postgresql 
    else 
     install -d -m 2775 -o postgres -g postgres /var/run/postgresql 
    fi 

    do_ctl_all start "$1" "Starting PostgreSQL $1 database server" 
} 

這個函數創建目錄,所以當它缺少,這是大概是因爲PostgreSQL的未啓動,而不是相反,PostgreSQL不能啓動,因爲目錄不存在。