1
1

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.

【備忘録】PostgreSQLを導入してみたのでまとめてみた

Posted at

Introduction

ずっとMySQLばかりしか使っておらず、初めて PostgreSQLを触りはじめてみたので
備忘録としてまとめを記載

環境

Date: 2020/02/25
OS : macOS Catalina (10.15.3)

インストール方法

Homebrew

本手順は Homebrew を使ってインストールを行います。
※もしまだの方は参考文献をご参照ください

$ brew install postgresql

初期化

$ initdb /usr/local/var/postgres -E utf8

導入時にもし下記のような文がでるなら、/usr/local/var/配下にあるpostgresqlディレクトリを削除して、もう一度同じコマンドを入力してみましょう

initdb: directory "/usr/local/var/postgres" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/usr/local/var/postgres" or run initdb
with an argument other than "/usr/local/var/postgres".

バージョン

$ postgres --version

postgres (PostgreSQL) 12.1

起動

$ pg_ctl -D /usr/local/var/postgres -l logfile start

一覧

$ psql -l

                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges
-----------+----------+----------+---------+-------+-----------------------
 postgres  | username | UTF8     | C       | C     |
 template0 | username | UTF8     | C       | C     | =c/username          +
           |          |          |         |       | username=CTc/username
 template1 | username | UTF8     | C       | C     | =c/username          +
           |          |          |         |       | username=CTc/username
(3 rows)

接続

$ psql -U username postgres

psql (12.1)
Type "help" for help.

postgres=#
postgres=#

参考文献

1
1
0

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?