Posts

Showing posts with the label psql

How to start and stop PostgreSQL server?

On Windows First, you need to find the PostgreSQL database directory, it can be something like C:\Program Files\PostgreSQL\10.4\data. Then open Command Prompt and execute this command: pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" start To stop the server pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" stop To restart the server: pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" restart Another way: Open Run Window by Winkey + R Type services.msc Search Postgres service based on version installed. Click stop, start or restart the service option.

PostgreSQL Tutorial 1 -- psql is not recognized as an internal command windows

Image
While using postgreSQL command line utility " psql " command is giving error like " psql is not recognized as an internal command windows ". To solve this we have to follow below process.  1. Getting the error.  2. Temporary solution for the issue resolution.  3. Updating the " PATH " environment variable for applying the permanent changes.  4. Verifying the fix. Issue solved. 

PostgreSQL Tutorial 2 -- Increasing the CMD windows size

Image
Below is the process to increase the CMD window. 

PostgreSQL Tutorial 3 -- Connecting Postgresql through CMD and existing from CMD

Image
Below are the commands for connecting postgresql through CMD.  1. Connecting Postgresql through CMD 3. Existing from Postgresql from CMD.

PostgreSQL Tutorial 4 -- Findings DBs in Postgresql

Image
Below are the commands to get list of DBs in postgresql.

PostgreSQL Tutorial 5 -- Creating the DB in Postgresql and Switching between DBs

Image
A. Creating Database in Postgresql B. Swithcing between DBs

PostgreSQL Tutorial 6 -- Creating, Inserting and Select statments for Tables

Image
Below are the statments for Creating table, Inserting in to table and selecting the data. 

PostgreSQL Tutorial 8 -- Getting the Tables List in postgresql

Image
Below is the command to get the list of tables in postgresql. 

PSQL command to know the details of the table details

Image
Below is the process to know the details of the table in PSQL. 

How to redirect psql output to a text file

Image
Below is the process to redirect the psql output to a text file.  \o 'D:/temp/Customers_List.txt' SELECT * FROM Tst_ScripFile_Execu_PSQL; \o Please note that once after the query executed, we have to use again "\o" to stop the output redirecting.

How to execute script file in PSQL

Image
Some times we need to execute the script file in PSQL. Below is the procedure to execute the script file in psql.  we have to use command like  \i 'D:/temp/Postgresql_ScriptFile_20191030.sql'

How to write big queries in PSQL

Image
Suppose we are using PSQL (command line tool for postgresql) and want to write an big query like joins and where conditions. Here the problem is, as we are writing the query in command prompt, it will be hard to write big queries.  To solve this problem, we can use psql command " \e ", this command will open the last executed query in notepad file. In this file we can write our lengthy queries, then save the file and close the file. Once after closing the file, psql will execute the query and will provide the result. Here we have to note one thing, that is psql will not show the query that we just write in the notepad file, to check what query executed, we can again use the command " \e ".  Below is the examples of what we have read above. 

PSQL Commands References

1. When we connect Postgresql with particular user, if the user is Superuser or has the privilege Create DB , then the prompt will like " =# " otherwise it will look like " => " .  2. How to write big queries in psql.  https://venkataramanapostgresqlreference.blogspot.com/2019/10/how-write-big-queries-in-psql.html 3. How to execute script file in PSQL. https://venkataramanapostgresqlreference.blogspot.com/2019/10/how-to-execute-script-file-in-psql.html   4. How to redirect the output to a text file in PSQL.  https://venkataramanapostgresqlreference.blogspot.com/2019/10/how-to-redirect-psql-output-to-text-file.html 5. PSQL command to know the details of the table details. https://venkataramanapostgresqlreference.blogspot.com/2019/10/psql-command-to-know-details-of-table.html