Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location of postgresql database on OS X?

I'm sure this has been answered but I cannot seem to find an answer.

I installed postgresql using Homebrew (brew install postgresql) which installed to /usr/local/Cellar/postgresql. Afterwords per the instructions I did this:

If this is your first install, create a database with:     initdb /usr/local/var/postgres 

As I understand it, initdb creates a new cluster of databases. So when I did the above is "postgres" the database name and the database itself or just all the necessary bits that all postgresql databases will need?

Where does the actual database end up living? I am new to postgresql and looking for a file or binary that is the database. So, where is the database, and when I create a new one where does it go?

like image 210
crobison Avatar asked Feb 19 '11 19:02

crobison


People also ask

Where is my PostgreSQL database stored?

All the data needed for a database cluster is stored within the cluster's data directory, commonly referred to as PGDATA (after the name of the environment variable that can be used to define it). A common location for PGDATA is /var/lib/pgsql/data.


2 Answers

initdb just sets up the directory structure and such that is needed to create new databases. To create a database, use createdb:

SYNOPSIS
createdb [ option... ] [ dbname ] [ description ]

DESCRIPTION
createdb creates a new PostgreSQL database.

Normally, the database user who executes this command becomes the owner of the new database. However a different owner can be specified via the -O option, if the executing user has appropriate privileges.

createdb is a wrapper around the SQL command CREATE DATABASE [create_database(7)]. There is no effective difference between creating databases via this utility and via other methods for accessing the server.

initdb is sort of like creating a new file system on a hard disk: first you create the file system (initdb), then you create a files and directories (createdb).

The actual database files will be under /usr/local/var/postgres after you create the database. So, just create a database and then see what's new or changed under /usr/local/var/postgres. There isn't a single "dbname.db" file or anything like that, each database is a collection of files with names that are only meaningful to the database server.

like image 193
mu is too short Avatar answered Sep 22 '22 10:09

mu is too short


Run the following query:

SHOW DATA_DIRECTORY; 
like image 22
Mallikarjun Avatar answered Sep 20 '22 10:09

Mallikarjun