Bash Script to install PostgreSQL - Failing
As people say it looks like you don't have the PostgreSQL bin directory on your path. In my experience on Ubuntu with PostgreSQL 9.1/9.2 on install from apt, the postgres user is created but it doesn't properly set up your environment, so pg_ctl
and initdb
etc are not on your PATH
.
I can't see what PostgreSQL version you're using, but my 9.1 & 9.2 instances store the binaries in /usr/lib/postgresql/9.2/bin
Check that directory to see if it contains pg_ctl and other binaries. If it does,
try running:
export PATH=$PATH:/usr/lib/postgresql/9.2/bin
and see if that allows you to run pg_ctl
. If so, you'll need to execute that at login from .bashrc
or similar
Bash Script to install PostgreSQL - Not working
The part that is clearly wrong in your script is that it expects the lines following the su - postgres
to be run as the postgres user. This won't happen.
In batch mode, su - postgres
starts and immediately exits because no command is fed to it. Then the next commands of the scripts are executed as the user launching the script (presumably root) and they fail.
Instead, you should write something like this:
su - postgres <<-'EOF'
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/
/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
/usr/local/pgsql/bin/createdb test
EOF
# the lines after the EOF will be executed again as the initial user
The suggestions in the comments assume that you have installed postgresql via a package, but that's not the context of the question. When you install from source with ./configure
without arguments and make install
, it will never install anything outside /usr/local/pgsql
. It's perfectly normal to have no startup script under /etc
in this context.
Postgresql -bash: psql: command not found
perhaps psql isn't in the PATH
of the postgres user. Use the locate command to find where psql is and ensure that it's path is in the PATH
for the postgres user.
Postgres psql not recognized as an internal or external command
Just an update because I was trying it on Windows 10 you do need to set the path to the following:;C:\Program Files\PostgreSQL\14\bin ;C:\Program Files\PostgreSQL\9.5\lib
PS : 14 is the current version, check whatever version you are on.
You can do that either through the CMD by using set PATH [the path]
or from my
computer => properties => advanced system settings=> Environment
Variables => System Variables
Then search for path.
Important: don't replace the PATHs that are already there just add one beside them as follows ;C:\Program Files\PostgreSQL\9.5\bin ;C:\Program Files\PostgreSQL\9.5\lib
Please note: On windows 10, if you follow this: computer => properties => advanced system settings=> Environment Variables => System Variables> select PATH, you actually get the option to add new row. Click Edit, add the /bin and /lib folder locations and save changes.
Then close your command prompt if it's open and then start it again
try psql --version
If it gives you an answer then you are good to go if not try echo %PATH%
and see if the path you set was added or not and if it's added is it added correctly or not.
Important note:
Replace 9.5 with your current version number. As of 2021, that is 13.
For 2022 is 14.
PgAdmin on Windows 10 with Postgres when installed via Bash on Ubuntu on Windows
Here's what I did to connect Postgres DB installed in WSL Ubuntu from Windows pgAdmin.
- Launch Ubuntu in Windows.
- Start postgres in Ubuntu terminal:
sudo service postgresql start
- Download the latest pgAdmin and install in Windows.
- Launch pgAdmin, a new tab in browser opens; click on Add New Server link.
- In the popup Create - Server window in the browser:
- General tab: I set Name to localhost
- Connection tab: I set Host name/address to localhost, set Password to postgres, which is the default, click on
Save password?
- I save the setting, leaving the rest of the fields as is
- That's it, I can see the DB created in Postgres immediately.
Running Bash Script to Download SQL Server ODBC Driver in Databricks Fails
The reason behind this is not entirely clear, however, my best guesses are as follows,
- It has something to do with hidden characters in the file that is created locally. For instance, Windows might be adding carriage returns instead of new lines and this could be affecting the execution of the file.
- It has something to do with file permissions (upon checking the permissions on the file, however, this does not seem to be the case).
How I was able to resolve this issue is by simple creating the file inside of the Databricks workspace by using dbutils
. For example,
dbutils.fs.put("dbfs:/scripts/install_dependencies.sh","""
#!/bin/bash
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get -q -y install msodbcsql17""", True)
This runs without an issue and it seems to be the recommended way to create any init scripts that you want to run on your clusters.
The downside is that you can't exactly version control these scripts and will require them to be overwritten each time a change is required.
Related Topics
Spawn_Id: Spawn Id Exp6 Not Open
Double Free - Crash or No Crash
Linux Shell Script - Find All Files and Run a Command on Each One of Them
Using Awk to Get a Specific String in Line
_Ldg Causes Slower Execution Time in Certain Situation
How to Build Kernel Debug Info as Separate File
How to Populate /Dev with a Custom Directory with Udev
How to Configure/Make/Install Against an Older Version of a Library
The Behavior When a Gnu Make Phony Target Happens to Be The Same as a Directory Name
Launching Sonar Scanner from a Gitlab Docker Runner
How to Sort Files in Paste Command
How to Make Webdriver Testsuite Created in Windows Machine to Run in a Linux Box
How to Boot with My Latest Rpi-3.18.0 Kernel and Enabling The Device Tree
Compiling Kernel Error: Stdio.H: No Such File or Directory
Few Shell Commands Doesn't Work When I Invoke a Script via Qprocess in Qt