Hello,
So here I am writing another article about PostgreSQL. If you do not have this database installed and would like to learn and try about this database engine, check out my last post about installation: https://www.techdatabasket.com/postgresql-11-installation-on-centos-el7-x86_64/
After the installation we have to start the initdb file that creates a new PostgreSQL database cluster. This file can be invoked both through the command :
/usr/pgsql-11/bin/initdb
Where in this case /usr/pgsql-11/bin is the directory where the software is installed by default or you can also invoke this utility using this command:
/usr/pgsql-11/bin/pg_ctl initdb
Nevertheless the output, it will be something like this:
-bash-4.2$ /usr/pgsql-11/bin/initdb 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 database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". Data page checksums are disabled. fixing permissions on existing directory /var/lib/pgsql/11/data … ok creating subdirectories … ok selecting default max_connections … 100 selecting default shared_buffers … 128MB selecting default timezone … UTC 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: /usr/pgsql-11/bin/pg_ctl -D /var/lib/pgsql/11/data -l logfile start
However, at this point if you try to connect directly to the psql console you will receive this error:
-bash-4.2$ psql -l psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Then, to be able to connect properly to this console you must have to start the server:
-bash-4.2$ /usr/pgsql-11/bin/pg_ctl -D /var/lib/pgsql/11/data -l logfile start waiting for server to start…. done server started
And finally you can connect to the cluster console and list all the existing databases:
bash-4.2$ psql -l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres (3 rows) -bash-4.2$
Hi! I am Bruno, a Brazilian born and bred, and I am also a naturalized Swedish citizen. I am a former Oracle ACE and, to keep up with academic research, I am a Computer Scientist with an MSc in Data Science and another MSc in Software Engineering. I have over ten years of experience working with companies such as IBM, Epico Tech, and Playtech across three different countries (Brazil, Hungary, and Sweden), and I have joined projects remotely in many others. I am super excited to share my interests in Databases, Cybersecurity, Cloud, Data Science, Data Engineering, Big Data, AI, Programming, Software Engineering, and data in general.
(Continue reading)