19

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?

2

2 Answers 2

20

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.

Sign up to request clarification or add additional context in comments.

Comments

3

CREATE TABLESPACE fastspace LOCATION '/mnt/sda1/postgresql/data';

See the chapter about tablespaces in the manual.

3 Comments

Like I said, that reference does not show how to use tablespaces in a CREATE DATABASE command
Actually it does.
CREATE DATABASE name TABLESPACE = tablespace or you can set a default tablespace so that everything created will be in that table space like so: SET default_tablespace = tablespace;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.