I want to check in a script if PostgreSQL is installed or not on Linux and print the result. Any suggestions on how to do the check?
|
If it is debian based.
But I guess you can just try to launch it with some flag like Updated using "service postgres status". Try:
|
|||||||||||
|
There is no straightforward way to do this. All you can do is check with the package manager (rpm, dpkg) or probe some likely locations for the files you want. Or you could try to connect to a likely port (5432) and see if you get a PostgreSQL protocol response. But none of this is going to be very robust. You might want to review your requirements. |
|||||
|
Go to bin directory of postgres db such as /opt/postgresql/bin & run below command [...bin]# ./psql --version psql (PostgreSQL) 9.0.4 Here you go. |
|||
|
What about trying the If you were to run
But if Postgres is installed you'll get a response with the path to the location of the Postgres install:
Looking at
So it seems like as long as whatever scripting language you're using can can execute a terminal command you could send I do have postgres installed on my machine so I run the following
which tells me that the command returned 0, indicating that the Postgres executable was found on my machine. |
|||
|