Began to learn Python 2.7 + PostgreSQL 9.6.1. Python already has some experience, but I don’t have any experience with PostgreSQL. (Windows 8)

There is a database name_db , which I create with the following code:

 #!/usr/bin/python # -*- coding: utf-8 -*- from psycopg2 import connect import sys from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT con = None con = connect(user='postgres', password='poilk', port=5432) dbname = "name_db" con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) cur = con.cursor() cur.execute('CREATE DATABASE ' + dbname) cur.close() con.close() 

Questions:

  1. Where is the "name_db"? In the folder with the project it is not. Search engine in Windows also does not know such files. (... PostgreSQL \ 9.6 \ data - the path to the database when installing PostgreSQL)
  2. How to change the path to save the database file in the folder with the project .../db/ ?

    1 answer 1

    In PostgreSQL, the storage area of ​​databases on disk is called a cluster of databases . A database cluster is a set of databases managed by a single instance of a working server. It must be initialized before the first start of the server.

    From a file system perspective, a database cluster is one directory in which all data will be stored. Where exactly to store data, you are absolutely free to choose for yourself. There is no standard path, but often the data is placed in /usr/local/pgsql/data .

    The initdb command is used to initialize the database cluster. The cluster location in the file system is specified by the -D parameter, for example:

     $ initdb -D /usr/local/pgsql/data 

    Database cluster settings (along with other server options) are described in the postgresql.conf file.

    Now about the location of the files. For example, in my Debian with PostgreSQL 9.4, the database cluster was initialized to /var/lib/postgresql/9.4/main , and the configuration file is located /etc/postgresql/9.4/main/postgresql.conf .

    The list of databases created in the cluster can be viewed, for example, using the psql :

     $ psql -U postgres --list 

    PS I hope for more knowledgeable people who will complement the answer by pointing out where PostgreSQL files are usually located in Windows.