6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

簡易なpostgresテスト環境を作る手順

Posted at

手元で簡易なテスト用PostgreSQL環境作る手順を簡単にまとめておきます。

DockerでPostgreSQLサービス起動:

$ docker run --name postgres -d -p 5432:5432 postgres

コンテナーの中に入る:

$ docker exec -it postgres bash

psqlでユーザとデータベースを作る:

# su - postgres
No directory, logging in with HOME=/

$ psql  
psql (9.5.4)
Type "help" for help.

postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

postgres=# CREATE ROLE foobar LOGIN CREATEDB PASSWORD 'foobar';
CREATE ROLE

postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 foobar      | Create DB                                                  | {}

postgres=# CREATE DATABASE foobar OWNER foobar;
CREATE DATABASE

6
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?