Steps to recreate error:
brew uninstall postgresql
brew prune
brew install postgresql
run postgresql start commands
psql
yields:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Suggested fixes I have tried that don't work:
create missing symbolic link:
sudo mkdir /var/pgsql_socket/
sudo ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/
remove postmaster.pid file (same link as above):
rm /usr/local/var/postgres/postmaster.pid
create potentially "cleaned up" directories from upgrade:
mkdir -p /usr/local/var/postgres/{pg_tblspc,pg_twophase,pg_stat_tmp}/
touch /usr/local/var/postgres/{pg_tblspc,pg_twophase,pg_stat_tmp}/.keep
Related GitHub issue
Edit 1:
This article correctly speculates that there are multiple versions of postgres in use, and which pg_ctl must be specified (below). Strangely, there are two directories in /usr/local/var: postgre & postgres. If anybody knows which settings to update to use the proper pg_ctl command directly, I would appreciate it!
/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_ctl -D /usr/local/var/postgre start
I ran into the same issue and after looking at the log file I found one directory was missing:
$ tail /usr/local/var/postgres/server.log
FATAL: could not open directory "pg_tblspc": No such file or directory
Then I did $ mkdir /usr/local/var/postgres/pg_tblspc, restarted PostgreSQL and got:
$ tail /usr/local/var/postgres/server.log
FATAL: could not open directory "pg_replslot": No such file or directory
After redoing the process may times I eneded up creating the following directories and then successfully started PostgreSQL:
/usr/local/var/postgres/pg_tblspc
/usr/local/var/postgres/pg_replslot
/usr/local/var/postgres/pg_twophase
/usr/local/var/postgres/pg_logical
/usr/local/var/postgres/pg_logical/mappings
I hope this helps.
Related
I am trying to run psql with user postgres. When I run sudo su - postgres AND THEN psql from within the new session, it is working smoothly. In fact, the ~/.bashrc in that session with use postgres has the correct PATH.
However, if I run sudo -u postgres psql, I get sudo: psql: command not found. Even though the session where I am running this command (I use the FISH shell) has the correct PATH as well, and I can invoke psql without the full path with my user.
I need to invoke the command as sudo -u postgres psql, how can this behavior be explained?
Edit: if (from FISH) I switch to BASH and run sudo -u postgres psql, it works! I guess it has to do with the FISH path then...
Edit 2: The issue seems to be that the PATH is reset when using sudo.
➜ ~ psql
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "opc" does not exist
➜ ~ sudo -u postgres psql
sudo: psql: command not found
➜ ~ echo $PATH
/home/opc/.local /home/opc/.local/bin /usr/pgsql-15/bin /usr/pgsql-15/bin /usr/local/bin /usr/bin /usr/local/sbin /usr/sbin
➜ ~ sudo echo $PATH
/home/opc/.local /home/opc/.local/bin /usr/pgsql-15/bin /usr/pgsql-15/bin /usr/local/bin /usr/bin /usr/local/sbin /usr/sbin
➜ ~ sudo -u postgres /usr/pgsql-15/bin/psql
could not change directory to "/home/opc": Permission denied
psql (15.1)
Type "help" for help.
postgres=#
But if I echo $PATH with sudo, it seems fine...
This is caused by a sudo configuration that has the "secure_path" setting. This causes sudo to reset $PATH to a hardcoded "known safe" value. This might be enabled by your distribution.
When you run sudo bash, that bash will read its settings, including .bashrc, and if you set $PATH in that it will then, of course, have that $PATH again.
But if you run a command without going through a shell that resets $PATH, you'll get the hardcoded setting.
It's possible to change that setting by running sudo visudo and changing the line that says
Defaults secure_path="some:path:here"
to
Defaults !secure_path
An alternative is to just run the command via the fully qualified path, like
sudo -u postgres (command -s psql)
One more comment about your tests:
sudo echo $PATH
This doesn't do what you want. The $PATH will be expanded by the shell that runs sudo, and so sudo won't ever see anything but the value of it. It is exactly equivalent to running sudo echo /home/opc/.local /home/opc/.local/bin /usr/pgsql-15/bin ....
You might want to use something like
sudo env
or
sudo sh -c 'echo $PATH'
instead.
I am new to postgres and was following this tutorial for setting Up Physical Streaming Replication with PostgreSQL
In step 3 while running the following command:
sudo -u postgres rm -r /var/lib/postgresql/12/main/*
I was getting the following error
rm: cannot remove '/var/lib/postgresql/12/main/*': No such file or directory
while the /var/lib/postgresql/12/main/ clearly had many files if explored manually.
In desperation, I deleted all the files inside /var/lib/postgresql/12/main/ manually and now any of the further steps are not working.
I have even tried to uninstall and install postgresql-12 using
sudo apt-get --purge remove postgresql
and
sudo apt -y install postgresql-12 postgresql-client-1 respectively
I have even tried doing the whole process again from start and while running the following command:
sudo -u postgres psql
sudo pg_ctlcluster 12 main start
I got this error:
Job for postgresql#12-main.service failed because the service did not take the steps required by its unit configuration.
See "systemctl status postgresql#12-main.service" and "journalctl -xe" for details.
while resolving the above issue using :
sudo chown postgres.postgres /var/lib/postgresql/12/main/global/pg_internal.init
I got this error...
chown: cannot access '/var/lib/postgresql/12/main/global/pg_internal.init': No such file or directory
I think this is happening because of the manual deletion of all the files and folder in
/var/lib/postgresql/12/main/
Any help is much appreciated
Thanks
The glob * is evaluated by your regular user before the sudo is invoked, but your regular user can't see into that directory. So what gets sent to the postgres user is an order to remove the file with the literal name of '/var/lib/postgresql/12/main/*', which doesn't exist. You would need to have your shell that evaluated the glob be postgres, so it can see what it is doing before invoking rm. Something like:
sudo -u postgres bash -c 'rm -r /var/lib/postgresql/12/main/*'
For the rest of it, you didn't give enough details to know what is going on, like what was in the logs, or what were the directory listings at the time your command failed.
Pretext: this has been asked before and i've tried implementing several solutions from previous posters. The only thing i can seem to get working is running mongo as sudo.
I'm not exactly sure what i'm doing wrong. I'm trying to do a tutorial using mongodb and every time i try to run the software i get back an error that its in a read-only directory. I'm on a mac running OS Sierra, i can force run it with sudo but i know thats wrong. I've been searching for an answer for awhile and i have already adjusted the folder permissions to 775 and nothing, then 777, still nothing.
Any help pointing me in the right direction would be greatly appreciated!
to resolve the "warning soft rlimits to low" check out this link - https://gist.github.com/tamitutor/6a1e41eec0ce021a9718
Lets start over as you are bouncing around on what you are trying.
Open activity monitor and kill any mongod process.
Go to your terminal and type which mongo - lets say it shows you download directory
cd to that directory and you should be in the bin directory
cd /mongo download directory/bin
sudo bash
mkdir -p /data/db
chmod 777 /data
chmod 777 /data/db
ls -ld /data/db this will validate you see the data/db directory as 777
exit
You're back in your mongo bin directory - if you are in /usr/local/bin skip this part.
If you are not in /usr/local/bin you will need to copy the mongo files to /usr/local/bin
sudo bash
ls - make sure you are in the correct directory
cp * /usr/local/bin
exit
which mongo should now show /usr/local/bin
type mongod to start it
open a new terminal and type mongo to connect to the instance
I recommend downloading Robo 3T (formally RoboMongo) to quickly check that you can connect.
If you do those steps, you should have no issues connecting to your local Mongo instance.
Your mongod.conf files should be in /usr/local/etc - check there to confirm you have your local host set.
Should be like net:
bindIp:127.0.0.1
I install Postgresql on my Ubuntu with:
brew install postgres
now I have:
psql --version
psql (PostgreSQL) 9.5.0
How can I start the service automatically?
On my Mac with homebrew I can do it with:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
but how on Ubuntu with Linuxbrew?
I try with:
brew services start postgresql
but it says:
sh: 1: list: not found
Error: Could not read the plist for `postgresql`!
What to do?
Not quite automatic but a step in the right direction. On my system I did the following:
$ pg_ctl start -D $HOME/.linuxbrew/var/postgres -l logfile
You could simple create an alias in your .bash_profile or .bashrc something like:
alias poston="pg_ctl start -D $HOME/.linuxbrew/var/postgres -l logfile"
alias postoff="pg_ctl stop -D $HOME/.linuxbrew/var/postgres"
To test it all out (assuming you do not yet have a database on your machine) you can also create a database for your current user:
$ poston
$ createdb `whoami`
$ psql
I just updated to Mavericks and trying to get all my required tools and software in place.
My mongodb is not working after installing mongodb through brew.
I did: brew install mongodb --devel
Then, I ran mongod& on terminal. This gives me:
ERROR: dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
I tried creating a directory: mkdir -p /data/db and I got permission denied as the error.
I am referring to this website "http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/" and installing Mongo using Homebrew.
Has anyone faced this issue before? Where do I actually find /data/db directory to give permissions to it? I tried ls -la in my home folder, but couldn't find this directory.
Please ignore. Here is what helped me to solve the problem:
$ sudo mkdir -p /data/db/
$ sudo chown `id -u` /data/db