-
Notifications
You must be signed in to change notification settings - Fork 3
PostgreSQL setup
These brief instructions explain how to install an instance of PostreSQL Server to start developing web applications using the aiohttp-three-template.
If possible, it is recommended to install PostreSQL on a virtual machine (e.g. VirtualBox, VMWare, or Docker). When installing locally, or on a VirtualBox or VMWare virtual machine, it is recommended to follow this detailed blog post, providing useful information on how to install Postgres and set up a new user: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-16-04.
If a GUI is desired, it's recommended to install pgAdmin3.
These following instructions are needed only if the PostgreSQL has been installed on a host different than the development environment for the Python application.
To allow remote access in the local network, two files need to be configured:
- pg_hba.conf
- postgresql.conf Under Ubuntu, both files can be found under /etc/postgresql/9.5/main, where "9.5" is the installed version.
pg_hba.conf needs to be configured to allow local network connections, by adding a line like (NB: replace "10.0.0.0" with your local network ip:
#TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
host all all 10.0.0.0 255.255.255.0 md5
This step is described in this official Ubuntu documentation page.
postgresql.conf needs to be configured to listen to incoming connections from hosts different than the one running PostreSQL, by editing the following line:
# replacing this default:
listen_addresses = 'localhost'
# with this:
listen_addresses = '*'
After the configuration changes mentioned above, it is necessary to reload and restart PostreSQL:
sudo /etc/init.d/postgresql reload
sudo /etc/init.d/postgresql restart
Once the PostgreSQL is running and available from the host running the aiohttp development environment, use the db creation sql script and the tables creation script provided in the repository. The tables are required for the authentication, authorization and session management strategies included in the project template.
pgAdmin3 screenshot after configuration