Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I'm using Arch Linux (4.8.13-1-ARCH). I am attempting to set up PostgreSQL as instructed here.

After performing

[postgres@BitBox ~]$ initdb --locale $LANG -E UTF8 -D '/var/lib/postgres/data'
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgres/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

pg_ctl -D /var/lib/postgres/data -l logfile start

Successfully, I have returned to my regular user using the exit command.

[postgres@BitBox ~]$ exit
logout

Later, while trying to start postgresql.service, I am getting the below error:

[code_master5@BitBox ~]$ sudo systemctl start postgresql.service
Failed to start postgresql.service: Unit postgresql.service not found.

I'm don't even get the status of the service:

[code_master5@BitBox ~]$ sudo systemctl status postgresql.service
Unit postgresql.service could not be found.

Can anyone help me with this? 

3 Answers

0 votes
by (12.7k points)
edited by

You can try executing the following codes:

service postgresql-10.service restart
service postgresql-XX.service restart

Check out the SQL Tutorial to Learn SQL concepts in detail.

Start your SQL career with the best SQL Training course today!

0 votes
by (37.3k points)

It looks like postresql is not set up properly or is not installed properly in your system. So what you can do is you can follow the below steps to solve the particular issue:

Step 1: First check whether Postgresql is installed in your system or not. You can check that with the following command:

  • Pacman -Qs postgresql

If its not installed then execute the below command to install it 

  • Sudo pacman -S postgresql

Step 2: If you have not initialized the postgresql or you have just now installed the postgresql  then execute the following command to initialize the postgresql database

  • Sudo -io postgres

  • Initdb –locale $LANG -E UTF8 -D ‘/var/lib/postgres/data’

Step 3: Now enable and start the service with the following command if the postgresql has been initialized just now 

  • sudo systemctl enable postgresql.service

  • sudo systemctl start postgresql.service

Step 4: Check the status of postgresql to verify if it is working or not

  • sudo systemctl status postgresql.service

0 votes
by (3.1k points)

It’s a common error faced and can be resolved with some simple steps 

1. Check Service Status 

 Run the following command for more information about the status of the service: 

 

sudo systemctl status postgresql.service 

Look for error messages on why it might be failing. 

 

2. View Logs 

View PostgreSQL logs for any error messages: 

 

sudo journalctl -u postgresql.service 

This will provide more detailed logs of what went wrong during booting up. 

 

3. Configuration Issues 

Check if PostgreSQL configuration files are set correctly: 

 

Check the postgresql.conf and pg_hba.conf file for misconfiguration. Should be in /etc/postgresql/{version}/main/or /var/lib/pgsql/{version}/data/. 

4. Port Conflict 

Do not have another application or service using the port, which PostgreSQL is trying to work on. If PostgreSQL operates on 5432 default, the following should bring no output: 

 

sudo netstat -tuln | grep 5432 

5. File Permission 

Make sure, that the ownership and that the permission of the directory of PostgreSQL data is correctly set: 

sudo chown -R postgres:postgres /var/lib/postgresql/{version}/main/ 

Replace {version} with your version of PostgreSQL. 

6. Initializing the Database Cluster 

If this is the first PostgreSQL start, an initialization of the database cluster may also be required as follows (note that on some CentOS 7 installation, instead of /var/lib/postgres/data use /usr/local/pgsql/data with appropriate permissions in /usr/bin/postgres/postgres.conf 

sudo -u postgres /usr/pgsql-{version}/bin/initdb -D /var/lib/pgsql/{version}/data/ 

7. Start PostgreSQL 

Once above checks have been addressed start the service again as:  

sudo systemctl start postgresql.service  

8. Activate PostgreSQL to boot 

Add this line at the very end to get PostgreSQL auto-started  

sudo systemctl enable postgresql.service  

9. Test SELinux / App Armor 

If you use SELinux or AppArmor on your system, check the logs and configuration-they might be blocking the start of PostgreSQL. 

 

10. Reboot 

If everything fails, reboot your server and try to start the service again. 

Related questions

0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
asked Jan 1, 2021 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Dec 16, 2020 in SQL by Appu (6.1k points)

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...