blog.kirishikistudios.com

About Me   

Just another geek

twitter.com/satully:

    Install Postgresql in Mountain Lion

    I installed Postgresql on my Mac in order to use Heroku.

    Yamada-Naoyuki-MacBook-Pro:~ yamadanaoyuki$ brew install postgresql
    Warning: Your Xcode (4.4) is outdated
    Please install Xcode 4.4.1.
    ==> Downloading http://ftp.postgresql.org/pub/source/v9.1.4/postgresql-9.1.4.tar.bz2
    Already downloaded: /Library/Caches/Homebrew/postgresql-9.1.4.tar.bz2
    ==> Patching
    patching file src/pl/plpython/Makefile
    patching file contrib/uuid-ossp/uuid-ossp.c
    ==> ./configure --disable-debug --prefix=/usr/local/Cellar/postgresql/9.1.4 --datadir=/usr/local/Cel
    ==> make install-world
    ==> Caveats
    # Build Notes
    
    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/mxcl/homebrew/issues/issue/2510
    
    To build plpython against a specific Python, set PYTHON prior to brewing:
      PYTHON=/usr/local/bin/python  brew install postgresql
    See:
      http://www.postgresql.org/docs/9.1/static/install-procedure.html
    
    # Create/Upgrade a Database
    
    If this is your first install, create a database with:
      initdb /usr/local/var/postgres
    
    To migrate existing data from a previous major version (pre-9.1) of PostgreSQL, see:
      http://www.postgresql.org/docs/9.1/static/upgrading.html
    
    # Start/Stop PostgreSQL
    
    If this is your first install, automatically load on login with:
      mkdir -p ~/Library/LaunchAgents
      cp /usr/local/Cellar/postgresql/9.1.4/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
      launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
    
    If this is an upgrade and you already have the homebrew.mxcl.postgresql.plist loaded:
      launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
      cp /usr/local/Cellar/postgresql/9.1.4/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
      launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
    
    Or start manually with:
      pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
    
    And stop with:
      pg_ctl -D /usr/local/var/postgres stop -s -m fast
    
    # Loading Extensions
    
    By default, Homebrew builds all available Contrib extensions.  To see a list of all
    available extensions, from the psql command line, run:
      SELECT * FROM pg_available_extensions;
    
    To load any of the extension names, navigate to the desired database and run:
      CREATE EXTENSION [extension name];
    
    For instance, to load the tablefunc extension in the current database, run:
      CREATE EXTENSION tablefunc;
    
    For more information on the CREATE EXTENSION command, see:
      http://www.postgresql.org/docs/9.1/static/sql-createextension.html
    For more information on extensions, see:
      http://www.postgresql.org/docs/9.1/static/contrib.html
    
    # Other
    
    Some machines may require provisioning of shared memory:
      http://www.postgresql.org/docs/current/static/kernel-resources.html#SYSVIPC
    
    To install postgresql (and ossp-uuid) in 32-bit mode:
       brew install postgresql --32-bit
    
    If you want to install the postgres gem, including ARCHFLAGS is recommended:
        env ARCHFLAGS="-arch x86_64" gem install pg
    
    To install gems without sudo, see the Homebrew wiki.
    ==> Summary
    /usr/local/Cellar/postgresql/9.1.4: 2751 files, 36M, built in 117 seconds
    
    

    Initializing Database

    Yamada-Naoyuki-MacBook-Pro:~ yamadanaoyuki$ initdb /usr/local/var/postgres
    The files belonging to this database system will be owned by user "yamadanaoyuki".
    This user must also own the server process.
    
    The database cluster will be initialized with locale ja_JP.UTF-8.
    The default database encoding has accordingly been set to UTF8.
    initdb: could not find suitable text search configuration for locale ja_JP.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 ... 20
    selecting default shared_buffers ... 1600kB
    creating configuration files ... ok
    creating template1 database in /usr/local/var/postgres/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
    
    WARNING: enabling "trust" authentication for local connections
    You can change this by editing pg_hba.conf or using the -A option the
    next time you run initdb.
    
    Success. You can now start the database server using:
    
        postgres -D /usr/local/var/postgres
    or
        pg_ctl -D /usr/local/var/postgres -l logfile start
    

    Starting Server (Manually)

    Yamada-Naoyuki-MacBook-Pro:~ yamadanaoyuki$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
    server starting
    

    Displaying list of database

    Yamada-Naoyuki-MacBook-Pro:~ yamadanaoyuki$ psql -l
                                             List of databases
       Name    |     Owner     | Encoding |   Collate   |    Ctype    |        Access privileges        
    -----------+---------------+----------+-------------+-------------+---------------------------------
     postgres  | yamadanaoyuki | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | 
     template0 | yamadanaoyuki | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/yamadanaoyuki               +
               |               |          |             |             | yamadanaoyuki=CTc/yamadanaoyuki
     template1 | yamadanaoyuki | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/yamadanaoyuki               +
               |               |          |             |             | yamadanaoyuki=CTc/yamadanaoyuki
    (3 rows)
    

    Console Login

    Yamada-Naoyuki-MacBook-Pro:~ yamadanaoyuki$ psql postgres
    psql (9.1.4)
    Type "help" for help.
    
    postgres=#
    

    Logout from console

    postgres=# \q
    

    Create User, create DB

    Yamada-Naoyuki-MacBook-Pro:~ yamadanaoyuki$ createuser -P postgres
    Enter password for new role: 
    Enter it again: 
    Shall the new role be a superuser? (y/n) y
    Yamada-Naoyuki-MacBook-Pro:~ yamadanaoyuki$ createdb mydb -U postgres
    Yamada-Naoyuki-MacBook-Pro:~ yamadanaoyuki$ psql -l
                                             List of databases
       Name    |     Owner     | Encoding |   Collate   |    Ctype    |        Access privileges        
    -----------+---------------+----------+-------------+-------------+---------------------------------
     mydb      | postgres      | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | 
     postgres  | yamadanaoyuki | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | 
     template0 | yamadanaoyuki | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/yamadanaoyuki               +
               |               |          |             |             | yamadanaoyuki=CTc/yamadanaoyuki
     template1 | yamadanaoyuki | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/yamadanaoyuki               +
               |               |          |             |             | yamadanaoyuki=CTc/yamadanaoyuki
    (4 rows)
    
    
    — 9 months ago with 3 notes
    #postgresql  #heroku 
    1. chokkoyamada posted this