1

I am using Postgres 9.6 Standard. All databases keep their files in subdirs of the "base" dir of the data directory assigned to server when installing it. New and restored databases also keep their files in that dir only

Is it possible, if not in ver 9.6 then in later versions of Postgres, to create or restore a database so that its files be in any OTHER dir, the dir that I want? My disk where the "base" dir resides, is running out of space

I know that in Microsoft SQL Server and in Oracle, I can easily keep a database in any dir at all. Is the same available on Postgres?

asked May 11 at 1:23
4
  • You mean you want to have multiple databases of the same server (db cluster) in independent and arbitrary directories? Commented May 11 at 3:20
  • 3
    You'll probably want to look into tablespaces Commented May 11 at 3:32
  • 3
    Version 9.6 is EOL for a long time Commented May 11 at 6:25
  • Read versioning policy, in particular the EOL for 9.6. Commented May 11 at 15:15

1 Answer 1

2

Yes, that feature is known as "tablespace".

First, you have to create a directory. Let me assume that you are using Windows. Then run something like the following on your command line:

mkdir D:\wherever\tbsp

Then, run an SQL statement as superuser create a tablespace:

CREATE TABLESPACE tbsp LOCATION 'D:\wherever\tbsp';

Now you can create a database in that tablespace:

CREATE DATABASE newdb TABLESPACE tbsp;

However, this procedure gives me a feeling of the 20th century. I am not going to ask how old your hardware and your operating system is. All I will recommend is that you update your setup to something current, where you can just extend a logical volume.

answered May 11 at 6:38
2
  • Yes, I am from the 20th century :) I bought my first IBM-compatible computer in 1991. And now I am still using a notebook bought in 2014, running Windows 7 on it, Oracle 11, and MSSQL 2014. And I am not going to upgrade to Windows 10 till the end :) The higher is version of Windows or Postgres, or of anything, - the slower that software operates. Thank you very much! your advice of using tablespaces in Postgres is perfect, just what I needed Commented May 11 at 10:51
  • 4
    I wrote punched cards in the early eighties, but I don't share your position concerning upgrades. Commented May 11 at 11:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.