# Setting Postgres For Pagure

I normally use Sqlite for development because of the ease you get to see your file , browse through it and edit it. Having said that sqlite is good for development and not for production one of the foremost reason being it doesn’t support multi-thread querying.

The other disadvantage was sqlite doesn’t give a damn if you have dangling Foreign Key references, I land up on this problem recently. The way we categorize fork project in Pagure is on the basis of `parent_id` so if a project has `parent_id` its a fork and if it doesn’t then its not a fork.

This works out quite well unless recently we figured out a flaw , what if the main project is deleted, the expected behavior is the fork should be accessible but because of the `parent_id`  dependency the fork was getting inaccessible this was because as you delete the main repo , the FK references with the fork gets modified and becomes Null.

This creates anomaly because now the project is no more a fork , its a main repo and its treated like it which leads to a lot of repo path chaos. The relation of Postgres came here because I was able to have a dangling FK reference here in sqlite but when I try to achieve the same thing in Postgres it throws an integrity error.

Pagure uses Sqlalchemy as the ORM so I just need to set up postgres on my system and provide the URL in `pagure/default_config.py`  and ORM magic makes all the queries just work.

Setting up Postgres is really easy because of the amazing documentation provided in [fedora-wiki](https://fedoraproject.org/wiki/PostgreSQL) . The only thing you need to care or a little tricky about is you need to be a `superuser`  before you change to user `postgres` .  So first `sudo su` and then `su - postgres`. Then the follow the steps in the wiki and create a user and create a database name `pagure`.
