sudo: psql: command not found: can't fix it - linux

When I run
sudo -u postgres psql
I get the
sudo: psql: command not found
error. I can't get it to work.
# locate psql
/etc/alternatives/psql.1.gz
/usr/bin/psql
/usr/lib/postgresql/9.5/bin/psql
/usr/lib/x86_64-linux-gnu/odbc/libodbcpsqlS.so
/var/lib/dpkg/alternatives/psql.1.gz
/var/lib/postgresql/.psql_history
and
# ln -s /usr/lib/postgresql/9.5/bin/psql /usr/bin/psql
ln: failed to create symbolic link '/usr/bin/psql': File exists
Didn't work. Postgresql is running and doing fine, though.

Set up postgres' PATH variable in .bash_profile to contain /usr/lib/postgresql/9.5/bin.

copy the psql binary from the postgreql bin folder to /usr/bin
sudo cp -v /usr/lib/postgresql/9.5/bin/psql /usr/bin/

Related

Flutter for fedora 37

I'm trying to install flutter on Fedora 37 with snapd but it's not working. Whenever I try to use the command:
sudo snap install flutter --classic
I get the error:
Classic confinement requires snaps under /snap or symlink from /snap to /var/lib/snapd/snap.
Then I run the command:
sudo ln -s /var/lib/snapd/snap /snap
I get the error:
Failed to create symbolic link "snap/snap": File exists.
How do I fix this or find another way to use flutter on Fedora 37?
[ninal#fedora ~]$ sudo ln -s /var/lib/snapd/snap /snap
ln: failed to create symbolic link '/snap/snap': File exists
[ninal#fedora ~]$ sudo snap install flutter --classic
error: cannot install "flutter": classic confinement requires snaps under /snap
or symlink from /snap to /var/lib/snapd/snap
[ninal#fedora ~]$
Sudo or not, ln -s will always fail if the link file already exists. In order to overwrite there is a --force option you can use overwrite an existing link file.
However, the error message "snap/snap": File exists. indicates that you already have a directory named /snap in which a new snap symlink is attempted to be created.
So ln behaves in two different modes, either the last argument is the name of
the link file or
a directory where the link file is to be created within
$ cd /tmp
$ mkdir -p a/b/c
$ ln -s /tmp/a/b # First time, create "b" symlink in /tmp
$ ln -s /tmp/a/b # Second time, fails since symlink exists
ln: failed to create symbolic link './b': File exists
$ ln -sf /tmp/a/b # Succeds, overwrites existing symlink
$ mkdir c
$ ln -s /tmp/a/b/c c # First time, create "c" symlink inside /tmp/c directory
$ ln -s /tmp/a/b/c c # Second time, fails since symlink exists
ln: failed to create symbolic link 'c/c': File exists
$
For your particular scenario you need to get rid of the existing /snap directory to create the expected symlink.
sudo mv /snap /snap.old
sudo ln -s /var/lib/snapd/snap /snap

Error while trying to install Kops on Ubuntu 20 EC2 Instance

I went through the steps listed here: https://kubernetes.io/docs/setup/production-environment/tools/kops/
After moving the kops file to /usr/local/bin/ and renaming to kops, I tried to confirm if it was in fact installed and executable by trying 'kops --help' and 'kops --version'/'kops version' and neither command worked. Any idea what the issue might be?
Edit: Here's what I did step by step
curl -LO https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-darwin-amd64
sudo chmod +x kops-darwin-amd64
sudo mv kops-darwin-amd64 /usr/local/bin/kops
It's a t2.micro Ubuntu 20.04 EC2 Instance.
Tried to confirm if kops was properly installed and executable by entering 'kops --help' and 'kops --version' and also 'kops version' but they all return this error:
-bash: /usr/local/bin/kops: cannot execute binary file: Exec format error
I think its because you are using kops-darwin-amd64. This is for mac. I think you should be using kops-linux-amd64 instead for linux.

Postgresql cannot change to root with -u shortcut

Recently updated from Postgresql 9.1 to 9.3.
Everything works fine, but I noticed now when I type in:
sudo -u postgres psql
I am getting hit with a permission denied error for changing dir to root.
"Could not change directory to /home/root.
However, when I use:
sudo su - postgres
psql
It accesses it fine. How can I fix this?
change directory to someplace that postgres has access to:
cd /tmp
sudo -u postgres psql
Try this:
sudo -i -u postgres psql
This accomplishes (almost) the same thing as your
sudo su - postgres
The - in the above indicates that you want to use the postgres account's environment. If you remove the -, it will fail similarly to sudo -u
The -i indicates that you want to run the postgres account's login shell (hence cding to their home directory).
For me this did the trick (or you'll get a could not change directory to "/root": Permission denied), pay attention to quotes (')
sudo -Hiu postgres 'pg_dump --column-inserts --data-only --table=someTable entities_db > /var/backups/anywhere/$(date +%Y%m%d_%H%M%S)_someTable.sql'
Note the -Hiufor sudo, or use su - postgres
you can also put that in a cronjob for root with crontab -e

"cannot write to log file pg_upgrade_internal.log" when upgrading from Postgresql 9.1 to 9.3

I keep on getting the above error whenever I run the following command via a postgres user.
/usr/lib/postgresql/9.3/bin/pg_upgrade \
-b /usr/lib/postgresql/9.1/bin/ \
-B /usr/lib/postgresql/9.3/bin/ \
-d /var/lib/postgresql/9.1/main \
-D /var/lib/postgresql/9.3/main
cannot write to log file pg_upgrade_internal.log Failure, exiting
I'm using Ubuntu 13.10. Both Postgresql 9.1 and 9.3 are running properly.
Make sure that you run this command from a directory that is writable by the postgres user, like /tmp or /var/lib/postgresql:
$ cd /tmp
$ usr/lib/postgresql/9.3/bin/pg_upgrade ...
#run pg_upgrade command in new data directory path.
Ex: bash-4.2$ pwd
/var/lib/pgsql/11/data
bash-4.2$ /usr/pgsql-11/bin/pg_upgrade --old-datadir=/var/lib/pgsql/10/data --new-datadir=/var/lib/pgsql/11/data --old-bindir=/usr/pgsql-11/bin --new-bindir=/usr/pgsql-11/bin -c

Enable Postgresql in Cygwin

I installed Cygwin with Perl and Postgresql packages enabled.
Then typed:
/usr/bin/cygserver-config (This will install the service)
Then type:
net start cygserver(This starts the service)
Next i need to enable Postgresql in Cygwin, so i tried the commands mentioned below:
cygrunsrv -S cygserver
initdb -D /usr/share/postgresql/data
pg_ctl start -D /usr/share/postgresql/data -l /var/log/postgresql.log
createdb
psql
I get an error:
$ initdb -D /usr/share/postgresql/data
-bash: initdb: command not found
$ pg_ctl start -D /usr/share/postgresql/data -l /var/log/postgresql.log
-bash: pg_ctl: command not found
Can someone please tell me how to get it right.
The Postgresql initdb and pg_ctl executables are located under /usr/sbin.
I am guessing that /usr/sbin is not on your PATH setting. Adding it should do the trick.
I use a start/stop script which I keep under $HOME/bin called pg. Here's the gist.

Resources