[Mac] install postgresql

Published by onesixx on

https://sites.google.com/site/nitinpasumarthy/blog/installingpostgresonmac

 설치

0. 기설치 여부 확인 in Homebrew

~$➜ brew search postgresql
~$➜ brew services list

1. Homebrew를 통해 설치

~$➜ brew install postgres

2. 서비스 시작

~$➜ brew services start postgresql
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)

<참고> 다른 방법

~|⇒ mkdir -p ~/Library/LaunchAgents
~|⇒ ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
~|⇒ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

⇒  pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log restart
waiting for server to shut down.... done
server stopped
server starting

서비가 시작되면 DBeaver…

3. 초기설정

신규 DB 생성

~$➜ initdb /usr/local/var/postgres
The files belonging to this database system will be owned by user "onesixx".
This user must also own the server process.

The database cluster will be initialized with locales
COLLATE: C
CTYPE: UTF-8
MESSAGES: C
MONETARY: C
NUMERIC: C
TIME: C
The default database encoding has accordingly been set to "UTF8".
initdb: could not find suitable text search configuration for locale "UTF-8"
The default text search configuration will be set to "simple".

creating directory /usr/local/var/postgres ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

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

혹시 아래와 같이 에러나면..
/usr/local/var/postgres 폴더의 이름을 변경해 준다. 
mv postgres postgres_old

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".

신규 admin 사용자 추가 (버전폴더<9.6.5>는 다를수 있으니 확인)

~$➜ cd /usr/local/Cellar/postgresql/9.6.5/bin/
~$➜ createuser -s postgres

psql에서 default user인  postgres사용자 비밀번호 변경

~|⇒ psql
postgres=# alter user postgres with password '1';
ALTER ROLE

<참고> psql 위치 찾기 
~|⇒ locate psql |grep /bin

아래와 같이 ….

~|⇒ locate psql |grep /bin
locate 실행안되면,
~|⇒ sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
아래와 같이 ....
|⇒  psql
psql: FATAL:  database "onesixx" does not exist
|⇒  psql -d template1
psql (9.6.5)
Type "help" for help.
template1-# \\q
|⇒  createdb
|⇒  psql -h localhost
psql (9.6.5)
Type "help" for help.

<참고> psql 

~$➜~|⇒ psql --help
psql is the PostgreSQL interactive terminal.

Usage:
psql [OPTION]... [DBNAME [USERNAME]]
General options:
-c, --command=COMMAND run only single command (SQL or internal) and exit
-d, --dbname=DBNAME database name to connect to (default: "onesixx")
-f, --file=FILENAME execute commands from file, then exit

PgAdmin 로 나머지 작업 실행

<참고> psql 그냥 사용하고 싶으면, 

⇒ psql -U postgres -h localhost
psql (9.6.5)
Type "help" for help.

postgres=#

Categories: Postgresql

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x