Mac OSX El Capitanã§Ruby on RailsããPostgreSQLã使ã åç·¨
Mac OSX 10.11.4 El Capitanã«PostgreSQL 9.5.1ãã¤ã³ã¹ãã¼ã«ãããã¨ãã¦ã試è¡é¯èª¤ããç¾½ç®ã«é¥ã£ãã®ã§è¨é²ãã¦ããã¾ãã
RailsããPostgreSQLã使ãããã®ä½æ¥ã¯ãå¾ç·¨ã«æ¸ãã¦ãã¾ãã
ç®æ¬¡
- ç®æ¬¡
- ããã«ãã¦ãã®å¿æ ã«è³ã£ãã
- PostgreSQLãMacã«ã¤ã³ã¹ãã¼ã«ãã
- PostgreSQLã®è¨å®
- åèï¼ç§ããããç½ ããã®è±åº
- åèè¨äº
- éçºç°å¢
ããã«ãã¦ãã®å¿æ ã«è³ã£ãã
Ruby on Railsãã¥ã¼ããªã¢ã«ãåèã«ãã¦Webã¢ããªãä½ããHerokuã«ãããã¤ãããã¨ãã¦ããã®ã§ãããHerokuã§ã¯æ¨æºã®ãã¼ã¿ãã¼ã¹ã§ããPostgreSQLã使ãã®ã§ãMacã«ãPostgreSQLãå ¥ãã¦ãproductionç°å¢(Herokuã«ãããã¤ããç¶æ )ã¨developmentç°å¢(èªåã®PCã®éçºç°å¢)ãåãã«ãããã¨èãã¾ããã
PostgreSQLãMacã«ã¤ã³ã¹ãã¼ã«ãã
ã¾ãã¯ãHomebrew
ã§PostgreSQL
ãã¤ã³ã¹ãã¼ã«ãã¾ãã
注ï¼ãã®æç¹ã§/usr/local/var/postgres
ãã£ã¬ã¯ããªãæ¢ã«åå¨ãã¦ããå ´åããã¼ã¸ã§ã³éãã«ããã¨ã©ã¼ãçããå¯è½æ§ãããã¾ããã¨è¨ãããç§ã®ç°å¢ã§ã¯ã¨ã©ã¼ãèµ·ãã¾ãããã¨ã©ã¼ãèµ·ããå¾ã®ãªãããããã¯ãç§ããããç½ ããã®è±åºã«è¨è¼ãã¦ãã¾ãã
$brew install postgresql ==> Installing dependencies for postgresql: readline ==> Installing postgresql dependency: readline ==> Downloading https://homebrew.bintray.com/bottles/readline-6.3.8.el_capitan.bottle.tar.gz ######################################################################## 100.0% ==> Pouring readline-6.3.8.el_capitan.bottle.tar.gz ==> Caveats This formula is keg-only, which means it was not symlinked into /usr/local. OS X provides the BSD libedit library, which shadows libreadline. In order to prevent conflicts when programs look for libreadline we are defaulting this GNU Readline installation to keg-only. Generally there are no consequences of this for you. If you build your own software and it requires this formula, youll need to add to your build variables: LDFLAGS: -L/usr/local/opt/readline/lib CPPFLAGS: -I/usr/local/opt/readline/include ==> Summary ðº /usr/local/Cellar/readline/6.3.8: 40 files, 2.0M ==> Installing postgresql ==> Downloading https://homebrew.bintray.com/bottles/postgresql-9.5.1.el_capitan.bottle.tar.gz ######################################################################## 100.0% ==> Pouring postgresql-9.5.1.el_capitan.bottle.tar.gz ==> Caveats If builds of PostgreSQL 9 are failing and you have version 8.x installed, you may need to remove the previous version first. See: https://github.com/Homebrew/homebrew/issues/2510 To migrate existing data from a previous major version (pre-9.0) of PostgreSQL, see: http://www.postgresql.org/docs/9.5/static/upgrading.html To migrate existing data from a previous minor version (9.0-9.4) of PosgresSQL, see: http://www.postgresql.org/docs/9.5/static/pgupgrade.html You will need your previous PostgreSQL installation from brew to perform `pg_upgrade`. Do not run `brew cleanup postgresql` until you have performed the migration. To load postgresql: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist Or, if you dont want/need launchctl, you can just run: postgres -D /usr/local/var/postgres ==> Summary ðº /usr/local/Cellar/postgresql/9.5.1: 3,118 files, 35M
ã¤ã³ã¹ãã¼ã«ãçµäºãããããªã®ã§ããã¼ã¸ã§ã³ã確èªãã¦ã¿ã¾ãã
$postgres --version postgres (PostgreSQL) 9.5.1
brew install postgresql
ã®Summaryã«æ¸ãã¦ããã¨ããããã¼ã¸ã§ã³9.5.1
ãã¤ã³ã¹ãã¼ã«ãããããã§ãã
PostgreSQLã®è¨å®
PostgreSQLãã¼ã¿ãã¼ã¹ã¯ã©ã¹ã¿ã®ä½æã¨åæå
initdb
ã³ãã³ãã§ããã¼ã¿ãã¼ã¹ã¯ã©ã¹ã¿(ãã¼ã¿ãã¼ã¹æ ¼ç´é å)ãä½æãåæåãã¾ãã
ãã¼ã¿ãã¼ã¹ã¯ã©ã¹ã¿ãä½æãããã£ã¬ã¯ããªã¯ä»»æã®å ´æãé¸æã§ããããã§ãããä»åã®éçºç°å¢ã§ã¯ä¸è¬çã«ä½¿ããã¦ãã/usr/local/var/postgres
ãã£ã¬ã¯ããªã«ä½æãã¾ãã
ã¾ããåæåã®éã«ã¯å¿µã®ãããã¨ã³ã³ã¼ãã£ã³ã°ãUTF-8
ã«è¨å®ãã¦ããã¾ãã
- initdb ⦠PostgreSQLã®ãã¼ã¿ãã¼ã¹ã¯ã©ã¹ã¿ãæ°ããä½æããã³ãã³ã
- -E utf8 ⦠ãã¼ã¿ãã¼ã¹ã®ã¨ã³ã³ã¼ãã£ã³ã°ãUTF-8ã«è¨å®ãããªãã·ã§ã³
- /usr/local/var/postgres ⦠ãã¼ã¿ãã¼ã¹ã¯ã©ã¹ã¿(ãã¼ã¿ãã¼ã¹æ ¼ç´é å)ãä½æãããã£ã¬ã¯ããª
$initdb -E utf8 /usr/local/var/postgres The files belonging to this database system will be owned by user "b0npu". This user must also own the server process. The database cluster will be initialized with locale "ja_JP.UTF-8". initdb: could not find suitable text search configuration for locale "ja_JP.UTF-8" The default text search configuration will be set to "simple". Data page checksums are disabled. 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".
UTF-8
ã§ãã±ã¼ã«*1ã®åæåã¯ã§ããããã§ããã表示ãããæåã«ãData page checksums are disabled
ã¨ãdirectory "/usr/local/var/postgres" exists but is not empty
ã¨ãä¸ç©ãªæåã並ãã§ããäºã«ä¸å®ãé ãã¾ããã
調ã¹ã¦ã¿ãã¨ãData page checksums are disabled
ã¯-k
ãªãã·ã§ã³ã«ãããã¼ã¿ãã¼ã¸ã®ãã§ãã¯ãµã ãæå¹åããã¦ããªãããã«è¡¨ç¤ºãããdirectory "/usr/local/var/postgres" exists but is not empty
ã¯brew install postgresql
ã®æç¹ã§ã/usr/local/var/postgres
ããã¼ã¿ãã¼ã¹ã¯ã©ã¹ã¿ã¨ãã¦ä½æããã¦ããããã«è¡¨ç¤ºããã¦ããããã§ãã
ãªã«ãã¨ãããããã¼ã¿ãã¼ã¹ã¯ã©ã¹ã¿ãåæåããããããªã®ã§PostgreSQLãµã¼ããèµ·åãã¦ãåä½ç¢ºèªã試ã¿ã¾ãã
注ï¼PostgreSQLãµã¼ãã®ååèµ·åæã«FATALã¨ã©ã¼ãåºç¾ããããããªãããããã¨åã¤ã³ã¹ãã¼ã«ãããã¨ã«ãã¾ããã
ããããå
ã¯ãåã¤ã³ã¹ãã¼ã«å¾ã®ä½æ¥ã®è¨è¿°ã§ãããªãããããã®é¨åã¯ãç§ããããç½ ããã®è±åºã«è¨è¼ãã¦ãã¾ãã
$postgres -D /usr/local/var/postgres LOG: database system was shut down at 2016-04-05 05:17:18 JST LOG: MultiXact member wraparound protections are now enabled LOG: database system is ready to accept connections LOG: autovacuum launcher started
PostgreSQLãµã¼ããç¡äºã«èµ·åãã*2ãããªã®ã§ãpsql
ã³ãã³ããã§PostgreSQLã¤ã³ã¿ã©ã¯ãã£ãã¿ã¼ããã«ã®åä½ç¢ºèª*3ãã¦ããã¼ã¿ãã¼ã¹ã®ãªã¹ãã表示ãã¦ã¿ã¾ãã
$psql -l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+-------+----------+-------------+-------------+------------------- postgres | b0npu | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | template0 | b0npu | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/b0npu + | | | | | b0npu=CTc/b0npu template1 | b0npu | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/b0npu + | | | | | b0npu=CTc/b0npu (3 rows)
psql
ã³ãã³ãã®åä½ç¢ºèªãã§ãã¾ããã®ã§PostgreSQLãµã¼ããåæ¢ãããã¨æã£ãã®ã§ãããSIGTERM
ã«ããåæ¢æ¹æ³ããåããããåä½ç¢ºèªã®ããã«èµ·åããã ãã®ããã°ã©ã ã®pid
ã調ã¹ã¦kill
ããã®ãé¢åãªã®ã§ctrl+c
ã§æ¢ãã¾ãã
^CLOG: received fast shutdown request LOG: aborting any active transactions LOG: autovacuum launcher shutting down LOG: shutting down LOG: database system is shut down
åæ¢ã§ããããã§ãããLOG: received fast shutdown request
ã¨è¡¨ç¤ºãããã®ãè¦ãã¨ãctrl+c
ã«ããåæ¢ã¯æ©è¨ã ã£ãæ°ããã¾ãã
PostgreSQLã®èµ·åã¨åæ¢ãç°¡åã§å®å ¨ã«ãã
postgres
ã³ãã³ãã§PostgreSQLãµã¼ããèµ·åã§ãã¾ããããã¦ã¼ãã£ãªãã£ã§ããpg_ctl
ã³ãã³ãã使ããã¨ã§ãPostgreSQLãµã¼ããå®å
¨ã§ç°¡åã«èµ·åãããåæ¢ãããã§ããããã§ãã
ã¾ããpostgres
ã¯ããã©ã«ãã§ã¯PostgreSQLãµã¼ãããã©ã¢ã°ã©ã³ãã§èµ·åãã¾ãããpg_ctl
ã¯ããã¯ã°ã©ã¦ã³ãã§èµ·åãããããPostgreSQLãµã¼ãã®èµ·åä¸ã«å¥ã®ã¿ã¼ããã«ã¦ã¤ã³ãã¦ãéãããããå¿
è¦ããªããªãã¾ãã
ç°å¢å¤æ°PGDATAãè¨å®ãã¦èµ·åã楽ã«ãã
pg_ctl
ã§æ¥½ããããããã·ã§ã«ã®è¨å®ãã¡ã¤ã«ï¼bash_profileã¨ãzshrc*4ã¨ãï¼ã«PostgreSQLã®ç°å¢å¤æ°PGDATA
ãè¨è¿°ããããã©ã«ãã®ãã¼ã¿ãã£ã¬ã¯ããªã®å ´æãè¨å®ãã¾ãã
# PostgreSQLã§ä½¿ãããã©ã«ãã®ãã¼ãã¼ã¹ãã£ã¬ã¯ããªãç°å¢å¤æ°ã«è¨å® export PGDATA=/usr/local/var/postgres
PGDATA
ãè¨å®ã§ããã®ã§ãpg_ctl
ã§PostgreSQLãµã¼ããèµ·åãã¦ã¿ã¾ãã
$pg_ctl start server starting $LOG: database system was shut down at 2016-04-05 05:27:49 JST LOG: MultiXact member wraparound protections are now enabled LOG: autovacuum launcher started LOG: database system is ready to accept connections
èµ·åã¯ã§ããããã§ããããµã¼ããã°ã®LOG
ãå¤ãªå ´æ*5ã«è¡¨ç¤ºããã¦æ¸æãã¾ããã
-l
ãªãã·ã§ã³ã使ç¨ãã¦ãµã¼ããã°ã®åºåå
ãæå®ãã¦ããªãã¨ããã®ããã«è¡¨ç¤ºãããå ´åãããããã§ãã
ã¾ããPGDATA
ãè¨å®ãã¦ããªãå ´åããããã©ã«ãã®ãã¼ã¿ãã£ã¬ã¯ããªä»¥å¤ã®ãã¼ã¿ãã¼ã¹ã¯ã©ã¹ã¿ãèµ·åãããå ´åã¯ãèµ·åæã«-D
ãªãã·ã§ã³ã使ç¨ãã¦ãã¼ã¿ãã£ã¬ã¯ããªãæ示ããå¿
è¦ãããããã§ãã
ãªã«ãã¨ããããèµ·åã®ç¢ºèªã¯ã§ããã®ã§ãµã¯ãã¨åæ¢ãã¾ãã
$pg_ctl stop waiting for server to shut down...LOG: received fast shutdown request LOG: aborting any active transactions .LOG: autovacuum launcher shutting down LOG: shutting down LOG: database system is shut down done server stopped
ã©ããããå®å ¨ãªãµã¼ãã®åæ¢ãã§ããããã§ã( â¢Ìã â¢Ì)Ùâ§
postgresql.confã§ãµã¼ããã°ã®åºåå ãè¨å®ãã
å¤ãªå ´æã«ãµã¼ããã°ã表示ããã¦æ¸æãã®ãé²ã*6ããããã¼ã¿ãã£ã¬ã¯ããª/usr/local/val/postgres
ã®ä¸ã«ããè¨å®ãã¡ã¤ã«postgresql.conf
ãç·¨éãã¦ããµã¼ããã°ãããã¹ããã¡ã¤ã«ã«åºåããããã«è¨å®ãã¾ãã
pg_ctl
ã®-l
ãªãã·ã§ã³ã§ãµã¼ããã°ã®åºåå
ãæå®ããæ¹æ³ãããããã§ããããµã¼ããèµ·åããã度ã«ãµã¼ããã°ã®åºåå
ãå
¥åããã®ãé¢åãªã®ã§ãè¨å®ãã¡ã¤ã«ãæ´»ç¨ãã¾ãã
$vi /usr/local/val/postgres/postgresql.conf # - Where to Log - log_destination = 'stderr' # Valid values are combinations of # stderr, csvlog, syslog, and eventlog, # depending on platform. csvlog # requires logging_collector to be on. # This is used when logging to stderr: logging_collector = on # Enable capturing of stderr and csvlog # into log files. Required to be on for # csvlogs. # (change requires restart) # These are only used if logging_collector is on: log_directory = 'pg_log' # directory where log files are written, # can be absolute or relative to PGDATA log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern, # can include strftime() escapes log_file_mode = 0600 # creation mode for log files, # begin with 0 to use octal notation
- log_destination ⦠æ¨æºã¨ã©ã¼åºåã¨ãsyslogã¨ãã®åºåå ãæå®ããé ç®
- logging_collector ⦠log_destinationããããã¹ããã¡ã¤ã«ã¸ã®åºåã許å¯ããé ç®
- log_directory ⦠ãã°ãã¡ã¤ã«ã®æ ¼ç´å ãã£ã¬ã¯ããª*7ãè¨å®ãã
- log_filename ⦠ãã°ãã¡ã¤ã«ã®ãã¡ã¤ã«åãæå®ããé ç®
- log_file_mode ⦠ãã°ãã¡ã¤ã«ã®ãã¼ããã·ã§ã³ãæå®ããé ç®
postgresql.conf
ã®è¨å®ãã§ããã®ã§ãPostgreSQLãµã¼ããèµ·åãã¦ãµã¼ããã°ã®ãã°ãã¡ã¤ã«ã¸ã®åºåã確èªãã¾ãã
$pg_ctl start server starting LOG: redirecting log output to logging collector process HINT: Future log output will appear in directory "pg_log".
ãµã¼ãèµ·åæã®è¡¨ç¤ºãå¤ãã£ãäºã«å°ãåã³ã¤ã¤ãPostgreSQLãµã¼ããåæ¢ãã¾ãã
$pg_ctl stop waiting for server to shut down.... done server stopped
ãµã¼ãåæ¢æã®è¡¨ç¤ºãå¤ãã£ã¦ãã¾ãã®ã§ãå¾ã¯ãã°ãã¡ã¤ã«ãä½æããã¦ããã°ä¸æ®µè½ã§ãã
$ls /usr/local/var/postgres/pg_log postgresql-2016-04-05_054032.log
$more /usr/local/var/postgres/pg_log/postgresql-2016-04-05_054032.log LOG: database system was shut down at 2016-04-05 05:30:39 JST LOG: MultiXact member wraparound protections are now enabled LOG: autovacuum launcher started LOG: database system is ready to accept connections LOG: received fast shutdown request LOG: aborting any active transactions LOG: autovacuum launcher shutting down LOG: shutting down LOG: database system is shut down
ã§ããã¼ã½(ï½¥Ïï½¥)/
å¾ç·¨ã«ç¶ãã¾ãã
åèï¼ç§ããããç½ ããã®è±åº
brew install postgresql
ã§PostgreSQLãã¤ã³ã¹ãã¼ã«ãã¦initdb
ã§ãã¼ã¿ãã¼ã¹ã¯ã©ã¹ã¿ã®åæåãå®è¡ããå¾ãPostgreSQLãèµ·åãããã¨ãããã¨ã©ã¼ã«ééãã¾ããã
$postgres -D /usr/local/var/postgres FATAL: database files are incompatible with server DETAIL: The data directory was initialized by PostgreSQL version 9.4, which is not compatible with this version 9.5.1.
FATAL?(ã»ã»;)
ãããããã¾ããã§ãããããã¼ã¸ã§ã³éãã§ã¨ã©ã¼ãèµ·ãã¦ãããã¨ã¯ä¼ãã£ã¦ããã®ã§FATAL: database files are incompatible with server
ã§ã°ã°ã£ã¦ã¿ãã¨ããã¡ãã®è°è«ã«èª¿ã¹æ¹ãè²ã
ã¨è¼ã£ã¦ããã®ãè¦ã¤ãããããåèã«ãã¦èª¿æ»ãããã¨ã«ãã¾ããã
ã¨ãããããã£ã¬ã¯ããªã®æ å ±ã表示ãã¦ã¿ã¾ãã
$ls /usr/local/var /usr/local/var/postgres /usr/local/var: cache postgres /usr/local/var/postgres: PG_VERSION pg_clog pg_multixact pg_subtrans postgresql.conf base pg_hba.conf pg_notify pg_xlog postmaster.opts global pg_ident.conf pg_stat_tmp postgresql.auto.conf server.log
ãã¼ã¸ã§ã³éãã¨ãè¨ããã¦ãå²ã«ãpostgres
ã«é¢ä¿ããããªãã£ã¬ã¯ããªã¯1ã¤ããç¡ãããã§ãããåãã¦è¦ããã£ã¬ã¯ããªã®ä¸èº«ãè¦ã¦ãæ£ç´ããããããªãã®ã§ãå¥ã®ãã¼ã¿ãã¼ã¹ã¯ã©ã¹ã¿ãä½æãã¦ã¿ããã¨ã«ãã¾ãã
ããããã°ã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".
ã¨ãæ¸ãã¦ã¾ãããã
$initdb -E utf-8 /usr/local/var/postgres9.5 The files belonging to this database system will be owned by user "b0npu". This user must also own the server process. The database cluster will be initialized with locale "ja_JP.UTF-8". initdb: could not find suitable text search configuration for locale "ja_JP.UTF-8" The default text search configuration will be set to "simple". Data page checksums are disabled. creating directory /usr/local/var/postgres9.5 ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting dynamic shared memory implementation ... posix creating configuration files ... ok creating template1 database in /usr/local/var/postgres9.5/base/1 ... ok initializing pg_authid ... ok initializing dependencies ... ok creating system views ... ok loading system objects descriptions ... ok creating collations ... ok creating conversions ... ok creating dictionaries ... ok setting privileges on built-in objects ... ok creating information schema ... ok loading PL/pgSQL server-side language ... ok vacuuming database template1 ... ok copying template1 to template0 ... ok copying template1 to postgres ... 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/postgres9.5 -l logfile start
ãªããããããåºã¦ãã(ï¾Ðï¾)
æ°ãããã¼ã¿ãã¼ã¹ã¯ã©ã¹ã¿ã®/usr/local/var/postgres9.5
ãä½æãããåæåãåºæ¥ããããªã®ã§ãä½æããããã¼ã¿ãã£ã¬ã¯ããªã®æ
å ±ã確èªãã¦ã¿ã¾ãã
$ls /usr/local/var /usr/local/var/postgres9.5 /usr/local/var: cache postgres postgres9.5 /usr/local/var/postgres9.5: PG_VERSION pg_dynshmem pg_notify pg_stat_tmp postgresql.auto.conf base pg_hba.conf pg_replslot pg_subtrans postgresql.conf global pg_ident.conf pg_serial pg_tblspc pg_clog pg_logical pg_snapshots pg_twophase pg_commit_ts pg_multixact pg_stat pg_xlog
ãªããããã£ãè¦ã/usr/local/var/postgres
ãããä¸èº«ãå¤ã(ãï¾Ð´ï¾)
ããã¾ã§ã®èª¿æ»ã§ãPostgreSQLã®ã¤ã³ã¹ãã¼ã«ã¯åºæ¥ã¦ãã¦ããã¼ã¿ã¯ã©ã¹ã¿ã®ä½æãåºæ¥ãããã©ãã/usr/local/var/postgres
ã¯ãã¼ã¸ã§ã³ãéããã使ããªãã¦ããã¼ã¸ã§ã³ãéãçç±ã¯ããããç§ã«ã¯ããããªãã¨ããäºãåãã£ãã®ã§ãç°å¢æ§ç¯ä½æ¥ãåã«é²ããããã®æã£åãæ©ãæ¹æ³ãèãã¾ãã
ããããããªãã°åã¤ã³ã¹ãã¼ã«ã ã
å
ã»ã©ã¤ã³ã¹ãã¼ã«ããã°ããã®PostgreSQLããbrew uninstall postgresql
ãã¾ãã
$brew uninstall postgresql Uninstalling /usr/local/Cellar/postgresql/9.5.1... (3,118 files, 35M)
念ã®ãããã£ã¬ã¯ããªãåé¤ãã¾ãã
$rm -rf /usr/local/var/postgres $rm -rf /usr/local/var/postgres9.5
æé¤ãçµãã£ãã®ã§ãåã¤ã³ã¹ãã¼ã«ã試ã¿ã¾ãã
$brew install postgresql ==> Downloading https://homebrew.bintray.com/bottles/postgresql-9.5.1.el_capitan.bottle.tar.gz Already downloaded: /Library/Caches/Homebrew/postgresql-9.5.1.el_capitan.bottle.tar.gz ==> Pouring postgresql-9.5.1.el_capitan.bottle.tar.gz ==> /usr/local/Cellar/postgresql/9.5.1/bin/initdb /usr/local/var/postgres ==> Caveats If builds of PostgreSQL 9 are failing and you have version 8.x installed, you may need to remove the previous version first. See: https://github.com/Homebrew/homebrew/issues/2510 To migrate existing data from a previous major version (pre-9.0) of PostgreSQL, see: http://www.postgresql.org/docs/9.5/static/upgrading.html To migrate existing data from a previous minor version (9.0-9.4) of PosgresSQL, see: http://www.postgresql.org/docs/9.5/static/pgupgrade.html You will need your previous PostgreSQL installation from brew to perform `pg_upgrade`. Do not run `brew cleanup postgresql` until you have performed the migration. To load postgresql: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist Or, if you dont want/need launchctl, you can just run: postgres -D /usr/local/var/postgres ==> Summary ðº /usr/local/Cellar/postgresql/9.5.1: 3,118 files, 35M
æåã«ã¤ã³ã¹ãã¼ã«ããæã¯ãä¾åé¢ä¿ã«ããreadline
ã¨ãããã¤ã³ã¹ãã¼ã«ããã¦ãã¾ããããä»åã¯PostgeSQLã®ã¿ãã¤ã³ã¹ãã¼ã«ãããããã§ãã
æ £ä¾çã«ããã¼ã¿ãã¼ã¹ã¯ã©ã¹ã¿ã®åæåããã¦ããã¾ãã
$initdb -E utf-8 /usr/local/var/postgres The files belonging to this database system will be owned by user "b0npu". This user must also own the server process. The database cluster will be initialized with locale "ja_JP.UTF-8". initdb: could not find suitable text search configuration for locale "ja_JP.UTF-8" The default text search configuration will be set to "simple". Data page checksums are disabled. 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".
ãã¯ãbrew install postgreql
ã®æç¹ã§ããã¼ã¿ãã¼ã¹ã¯ã©ã¹ã¿ãä½æããã¦ããããã§ä¸ç©ãªæåã並ãã§ãã¾ãããã¨ããããåæåãçµãã£ããããªã®ã§ãPostgreSQLãµã¼ããèµ·åãã¦ã¿ã¾ãã
$postgres -D /usr/local/var/postgres LOG: database system was shut down at 2016-04-05 05:17:18 JST LOG: MultiXact member wraparound protections are now enabled LOG: database system is ready to accept connections LOG: autovacuum launcher started
è¯ãã£ããç¡äºã«PostgreSQLãµã¼ããèµ·åããã(´ï¼Ïï¼ï½)
è±åºã®ã¾ã¨ã
initdb -E utf-8 /usr/local/var/postgres
ã§åæåã試ã¿ãéã®åºåã®æå¾ã®æ¹ã«ãIf you want to create a new database system, either remove or empty the directory "/usr/local/var/postgres"
ã¨æ¸ããã¦ããã®ã§ã/usr/local/var/postgres
ã®ä¸èº«ãåé¤ãã¦æ°ãããã¼ã¿ãã¼ã¹ã¯ã©ã¹ã¿ãä½æããã ãã§è¯ãã£ãããããã¾ããããèªåã®éå»ã®è¡ãããè¥ããã¯ãMac OSXã«ããã©ã«ãã§ä½æããã¦ãããã®ã ããã¨æ¨æ¸¬ãã¾ããã®ã§ããã£ã¬ã¯ããªèªä½ã®åé¤ã¨åã¤ã³ã¹ãã¼ã«ãå®æ½ãã¾ããã
次ããã¯ãä¸è¬çã«ä½¿ããã¦ãããã£ã¬ã¯ããªã«ç½ ãç¡ãã確èªãã¦ããä½æ¥ãã¾ãã
åèè¨äº
PostgreSQLã®ã¤ã³ã¹ãã¼ã«ã«ã¤ãã¦ã¯ããã¡ãã®è¨äºãåèã«ããã¦ããã ãã¾ããã
éçºç°å¢
- OSX 10.11.4 El Capitan
- ã¿ã¼ããã«ã¨ãã¥ã¬ã¼ã¿ï¼ Macã¿ã¼ããã«
- ã·ã§ã«ï¼ zsh
- ããã±ã¼ã¸ããã¼ã¸ã£ï¼ Homebrew - ãªã¬ã¼ã·ã§ãã«ãã¼ã¿ãã¼ã¹
- ORDBMSï¼ PostgreSQL 9.5.1
*1:ã¨ã³ã³ã¼ãã£ã³ã°ãªããã®è¨èªç°å¢
*2:èµ·åæã«ãããã¯ã¼ã¯åä¿¡æ¥ç¶ã®è¨±å¯ãæ±ããããã®ã§è¨±å¯ãã¦ããã¾ã
*3:ãã®æã¯PostgreSQLãµã¼ãããã©ã¢ã°ã©ã³ãã§èµ·åããããPostgreSQLãµã¼ããèµ·åãããã¿ã¼ããã«ã¦ã¤ã³ãã¦ã¨ã¯å¥ã®ã¿ã¼ããã«ã¦ã¤ã³ãã¦ãéãã¦ç¢ºèªãã¾ãã
*4:ç§ã¯zshã使ã£ã¦ããã®ã§ãã¡ãã«æ¸ãã¾ãã
*5:$ã表示ããã¦å ¥åå¾ ã¡ã«ãªã£ãããã«è¦ããå¾
*6:ãµã¼ããã°ã®åºåå ãè¨å®ãã¦ãã¦ãåºåå ã®ãã£ã¬ã¯ããªãä½æããã¦ããªãå ´åã¯ãµã¼ãã®ååèµ·åæã«å°ãå¤ãªäºã«ãªãå ´åãããããã§ã
*7:ç°å¢å¤æ°ã®PGDATAãè¨å®ãã¦ããã°PGDATAé ä¸ã®ãã£ã¬ã¯ããª