목차

PostgreSQL

Start / Stop

macOS에서 Server.app이 있으면 postgres가 기본으로 설치되어 있다. 9.4, 12.4 → 9.4는 잘되는데 12.4는 어떻게 하는지 모르겠다. brew을 이용하여 설치하ㅡㄴ 것을 추천한다.

Create User

SELECT * FROM PG_SHADOW;
SELECT * FROM pg_user;
\du
\du+
SELECT u.usename AS "Role name",
  CASE WHEN u.usesuper AND u.usecreatedb THEN
            CAST('superuser, create database' AS pg_catalog.text)
       WHEN u.usesuper THEN
            CAST('superuser' AS pg_catalog.text)
       WHEN u.usecreatedb THEN
            CAST('create database' AS pg_catalog.text)
       ELSE CAST('' AS pg_catalog.text)
  END AS "Attributes"
FROM pg_catalog.pg_user u
ORDER BY 1;
CREATE SCHEMA test;
CREATE USER xxx PASSWORD 'yyy';
ALTER USER xx password 'yyy';
GRANT ALL ON SCHEMA test TO xxx;
GRANT ALL ON ALL TABLES IN SCHEMA test TO xxx;
ALTER schema test owner TO xxx;
ALTER DATABASE mydb SET search_path TO boen;
CREATE ROLE testuser LOGIN PASSWORD 'password';
CREATE TABLESPACE testtablespace OWNER testuser LOCATION '/pgdata/testdbtablespace';
CREATE SCHEMA testschema AUTHORIZATION testuser;
ALTER SCHEMA testschema OWNER TO testuser;
CREATE DATABASE testdb WITH ENCODING 'UNICODE' OWNER testuser;
ALTER DATABASE testdb SET search_path TO testschema;
ALTER ROLE testuser SET search_path TO testschema;
GRANT ALL ON DATABASE testdb TO testuser;
ALTER ROLE testuser SET default_tablespace = testtablespace;
ALTER DATABASE testdb SET default_tablespace = testtablespace;
$ sudo -u postgres createuser --interactive
postgres=# CREATE ROLE postgres SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN REPLICATION BYPASSRLS;

Config file

listen_addresses = '*'

host all all 192.168.1.1/24 md5

SELECT name, setting, category
FROM pg_settings
WHERE category = 'File Locations';

psql Remote Connect

psql -h repository.mama.kr -U postgres -d postgres

Configuring postgresql.conf

$ find \ -name "postgresql.conf"
/var/lib/pgsql/9.4/data/postgresql.conf

Install

apt-get install postgresql

10 main 5432 down postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log

최초 접속

$ sudo -u postgres psql

Database 생성

Database 생성

CREATE DATABASE garam;

Database 삭제

DROP DATABASE garam;

접속

pg_hba.conf