Skip to content

Database setup

Peng edited this page Jan 16, 2018 · 4 revisions

Application Database Setup

System: Google Cloud, Ubuntu 12.04 LTS

Install

sudo apt-get update
sudo apt-get install postgresql-9.1 postgresql-client postgresql-contrib

If alerts

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_TIME = "zh_CN.UTF-8",
    LC_MONETARY = "zh_CN.UTF-8",
    LC_ADDRESS = "zh_CN.UTF-8",
    LC_TELEPHONE = "zh_CN.UTF-8",
    LC_NAME = "zh_CN.UTF-8",
    LC_MEASUREMENT = "zh_CN.UTF-8",
    LC_IDENTIFICATION = "zh_CN.UTF-8",
    LC_NUMERIC = "zh_CN.UTF-8",
    LC_PAPER = "zh_CN.UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

run

sudo apt-get install language-pack-zh-hans

Create DB

sudo su postgres
psql

Then create database, user, password.

CREATE DATABASE oracle;
\l
CREATE USER prophet WITH PASSWORD 'prophetpwd';
ALTER DATABASE oracle OWNER TO prophet;
psql -U prophet -d oracle -h 127.0.0.1 -p 5432

Remote Access

After setting firewall to allow access from 0.0.0.0 to database port (default 5432), we edit the PostgreSQL configuration file.

cd /etc/postgresql/9.1/main/
vim postgresql.conf
vim pg_hba.conf
  • In postgresql.conf, we set listen_addresses = '*' from listen_addresses = 'localhost';
  • In pg_hba.conf, we set for example
# IPv4 local connections:
host    eventscalendardb         dbusername         0.0.0.0/0          md5
/etc/init.d/postgresql start
/etc/init.d/postgresql restart
systemctl status postgresql.service