The Go Blog

postgresql 10.0

bantana
7 October 2017

introduction postgresql

introduct

install postgresql 10.0

  • mac
$brew edit postgres

 class Postgresql < Formula
  desc "Object-relational database system"
  homepage "https://www.postgresql.org/"
>  url "https://ftp.postgresql.org/pub/source/v10.0/postgresql-10.0.tar.bz2"
>  sha256 "712f5592e27b81c5b454df96b258c14d94b6b03836831e015c65d6deeae57fd1"

$brew install postgresql

will be install from source.

1. 语言字符集相关

$ cat .bash_profile

  [ -f /etc/profile ] && source /etc/profile
  PGDATA=/var/lib/pgsql/10/data
  export PGDATA
  # If you want to customize your settings,
  # Use the file below. This is not overridden
  # by the RPMS.
  [ -f /var/lib/pgsql/.pgsql_profile ] && source /var/lib/pgsql/.pgsql_profile

  LC_ALL=en_US.UTF-8
  export LC_ALL
  LANG=en_US.UTF-8
  export LANG
  LC_CTYPE=UTF-8
  export LC_CTYPE

2. initdb:

$pg_ctl init -D /usr/local/var/postgres

2. createdb:

$createdb

$psql

bantana=# select version();
                                                 version
-------------------------------------------------------------------------------------------------------------
 PostgreSQL 10.0 on x86_64-apple-darwin16.7.0, compiled by Apple LLVM version 9.0.0 (clang-900.0.37), 64-bit
(1 row)

bantana=#

Start Up Commands

CREATE USER

$ psql -U postgres -h 127.0.0.1 template1

template1=> create user nqq with password 'password';
CREATE ROLE
template1=> alter user nqq createdb;
ALTER ROLE
template1=>

USE new user connect postgresql

$ psql -U nqq -h 127.0.0.1 template0

CREATE DATABASE

template0=> create database nqq;

DROP DATABASE

template0=> drop database nqq;

DROP ROLE(USER) template0=> drop user nqqnew; DROP ROLE

Network allow access

modify listen_addresses in postgresql.conf

$ vi /usr/local/var/postgres/postgresql.conf

#listen_addresses = 'localhost'
listen_addresses = '*'

change to

listen_addresses = '*'

modify host allow in pg_hba.conf

$ vi /usr/local/var/postgres/pg_hba.conf

host    all             all             0.0.0.0/0               md5

Related articles