Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql: creating database in a specified location

Tags:

postgresql

I am trying to create a PG db in a specified location. According to the docs here, I must use the LOCATION flag. However, when I run CREATE DATABASE (from the pgsql CLI), I get the following warning:

WARNING:  LOCATION is not supported anymore
HINT:  Consider using tablespaces instead.

However, the PG documentation on TABLESPACES does not show how it can be used to create a database in a specific directory. What is the required syntax to do this?

like image 262
Homunculus Reticulli Avatar asked Mar 26 '12 16:03

Homunculus Reticulli


People also ask

How do I create a spatial database in PostgreSQL?

Open the Databases tree item and have a look at the available databases. The postgres database is the user database for the default postgres user and is not too interesting to us. Right-click on the Databases item and select New Database . Fill in the Create Database form as shown below and click OK.

How do I change the default database location in PostgreSQL?

Changing the Data folder Location on Postgresql Configuration Files. We can change the default data folder by editing the /etc/postgresql/9.5/main/postgresql. conf file and edit the data_directory. $ sudo vi /etc/postgresql/9.5/main/postgresql.

Where is postgres database location?

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.

Which are the methods PostgreSQL provides to create a new database?

PostgreSQL provides two methods for creating a new database: the CREATE DATABASE SQL command, and the createdb command-line executable.


1 Answers

You would need to do this in 2 steps:

  1. Create Tablespace examples for which you can see in the link
  2. Create Database

When you create tablespace you set it's location and then you can create multiple databases in the same tablespace if you choose to.

like image 163
Karlson Avatar answered Oct 11 '22 09:10

Karlson