Error in creating symlink for pg_wal in postgress - postgres-10

Stopped the postgresql service
Then moved pg_wal from "/var/lib/postgresql/11/main/ " to "/root/pg_xlog/archivedir"**
Created symlink using the command "ln -s /root/pg_xlog/archivedir /var/lib/postgresql/11/main/pg_wal **"
It created a "pg_wal->/root/pg_xlog/archivedir" under /var/lib **
And then tried to restart the postgresql main service, its showing error not getting restarted .
Then checked inside the log file .its shown below error like pg_wal directory not found but it is present as a pointer inside /var/lib/postgresql/11/main as shown above.
This symlink created as link for pg_wal inside /var/lib/postgresql/11/main/ for which , when tried to restart postgresql main its throwing error like
"required WAL directory "pg_wal" does not exist"
please suggest....

This would be easier to answer if you could reformat your question with the direct output from your terminal, but my suspicion is that you have a permission issue reading things under /root/pg_xlog/archivedir as the postgres (OS) user.
As a bonus tip, pointing the active wal dir to something that looks like an archive wal dir from an older version of Postgres seems like a dangerous idea.

Related

How to get postgres to start on big sur?

I'm attempting to launch a rails server on big sur (M1 chip) and postgres is giving the following error:
ActiveRecord::ConnectionNotEstablished (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"?
):
I've seen and tried several fixes but none have worked, including the following:
Reinstalling postgres via homebrew.
Reinstalling the pg gem.
brew services restart.
Trying to delete a postmaster.pid file (none exist). This directory: "/usr/local/var/postgres/postmaster.pid" does not exist on my machine.
My postgres.log file contains the following line repeating:
could not open directory "pg_notify": No such file or directory LOG: database system is shut down
While Genetic's answer works, a quicker solution would be to delete the partially created database (assuming you have just installed postgres and there's no data to be lost) and then run initdb as listed in brew info postgresql to recreate the database:
brew services stop postgresql
rm -rf "$(brew --prefix)/var/postgres"
initdb --locale=C -E UTF-8 "$(brew --prefix)/var/postgres"
brew services start postgresql
The original error on the console didn't change until I entered the following command:
brew services restart -vvv postgresql
After doing this, the errors updated. It then displayed the other directories and sub-directories that were missing. Once I added everything, all was fine.
The solution by anonymus_rex in the comments worked for me. Here are the exact steps I needed to take in case it could help anyone to elaborate a bit more. i was stuck on this for way too long.
I tried almost all of the answers in this question and this other one and this is what finally worked for me to get postgres to start
tail the logs for postgres.
the path needs to be updated depending on where postgres is installed, and your version. I am using postgresql#14 on an m1 Monterey and installed it with homebrew.
i finally found the path i needed to look at using this article.
tail /opt/homebrew/var/log/postgresql#14.log
output shows this:
2023-02-03 15:33:49.294 CST [82651] FATAL: could not open directory "pg_notify": No such file or directory
2023-02-03 15:33:49.294 CST [82651] LOG: database system is shut down
go to the / directory and cd opt/homebrew/var/postgresql#14
create the missing directory (maybe this is a different directory for you)
mkdir pg_notify
repeat this process for all missing directories.
I needed to mkdir for pg_tblspc, pg_replslot, pg_twophase, pg_stat_tmp, pg_logical/snapshots, pg_logical/mappings, pg_commit_ts, pg_snapshots, & pg_commit_ts but i recommend you specifically run the tail command each time to make sure you are not missing different directories & files than me.
finally after running the tail command repeatedly after creating each missing directory, I got this output.
2023-02-03 15:49:18.909 CST [85772] LOG: redo done at 0/17211D8 system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
2023-02-03 15:49:18.914 CST [85771] LOG: database system is ready to accept connections
i was then able to create & migrate my db in my project ・ᴗ・

Cp -Verbose outputs stating the file is copied, but the file actually doesn't show up

Facing a strange problem.
I tried running cp command in a script (Debian Lenny - Loaded with KDE).The verbose throws a message as if the file is copied but the file actually doesn't get copied until I manually refresh the destination folder.
Here is the copy command that I am trying to execute:
cp -v /data/publish/${VAR1}.txt ${VAR2}
FYI: VAR2- Variable holding the path to destination folder. In this case happens to be a usb drive.
The reason I call it a strange problem, is because I have no problems while executing this piece in Ubuntu, but facing problem in an another box running debian (loaded with KDE 3.5, I understand its pretty outdated).
Please help guys!

How do I put PostgreSQL /bin directory on my path in Windows?

I've got a fairly simple question I guess. I'm working on a Ruby on Rails app.
I'm trying to switch to PostgreSQL thanks to Heroku.
In my database.yml file it states:
Install PostgreSQL and put its /bin directory on your path.
My question is how do I put PostgreSQL's /bin directory on my path? Exactly which file do I modify and how?
I imagine this is my issue since when I run the "rails db" command i get:
"Couldn't find database client: psql,psql.exe. Check your $PATH and try again."
Thanks everyone!
Robin.
Append the directory to system PATH (not user PATH) by Environment Variables, using a semicolon to separate it from the previous entry.
You can find it from control pannel -> system -> Advanced -> Environment Variables
Ran into the same issue and tried the solution mentioned here
[user#host user]$
psql
bash: psql: command not found
[user#host user]$
echo $PATH
/bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin
[user#host user]$
export PATH=$PATH:/usr/local/pgsql/bin
[user#host user]$
psql testdb
Should do the trick.
You need to install Postgres first then add the path to system properties > environment variables > in system variables section you will see PATH variable
This is my preferred way of adding a new location to the PATH environment variable (on modern Red-Hat-based systems):
echo 'export PATH="/usr/pgsql-9.3/bin:$PATH"' | sudo tee /etc/profile.d/pgsql.sh
PATH is a colon : separated list of directories that are search, in order, for a called program.
Profile configurations under /etc are persistent for all users (but require the active shell to source them to take effect).
The version number is tacked on to the PostgreSQL directory when it is installed from their repository.

Postgresql fails to be recognised on the correct path

I'm trying to setup a new app with postgresql so I can deploy with Heroku. However, when I run the app using 'rails server' my welcome to rails screen gives this error:
PG::Error
could not connect to server: Permission denied Is the server running
locally and accepting connections on Unix domain socket
"/var/pgsql_socket/.s.PGSQL.5432"?
I'm sure this is the same issue as is covered here:
Repairing Postgresql after upgrading to OSX 10.7 Lion
But the fix by John Wang doesn't work.
I've tried adding 'export PATH=/usr/local/bin:$PATH' to the .bash_profile, .bashrc and .zshrc, none of which change the outcome. Calling which psql always returns /usr/bin/psql.
What am I doing wrong here? Any help would be much appreciated!
edit
Running /usr/local/bin/psql gives the same error and running echo $PATH gives:
/opt/local/bin:/opt/local/sbin:/Users/dave/.rvm/gems/ruby-1.9.3-p194/bin:/Users/dave/.rvm/gems/ruby-1.9.3-p194#global/bin:/Users/dave/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/dave/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/dave/.rvm/bin
What happens if you run your locally installed psql directly?
/usr/local/bin/psql ...
If that works then it's the path you need to change. You can just try running the export in a terminal, then which psql. If that doesn't pick up the right psql then check the export worked with
echo $PATH
I'm not sure which .xxrc file you'll need to update then - not got a mac to hand I'm afraid, but at least you'll know the command will work.
Oh - I keep several different versions of PostgreSQL around and find it useful to have some aliases set up:
alias psql90='/usr/local/pgsql90/bin/psql -p 5490'
alias psql84='/usr/local/pgsql84/bin/psql -p 5484'
alias pg_dump90=...
Your $PATH is just a list of directories to check separated by ":". It starts /opt/local/bin rather than /usr/local/bin and if you look further along you'll see /usr/bin coming before /usr/local/bin. So - we need to do two things:
Find out which psql we actually want
Make sure we can edit our PATH
Firstly - find your postgresql.conf file and check what port you are running on. There are three items of interest: listen_addresses, port and unix_socket_directory. Then we'll see if there's a socket there.
ls -a <your unix_socket_directory>
You should see a "file" something like ".s.PGSQL.5432" where the 5432 is the port number from your config file. If there's no such file, it's not running and it's time to get it running. You may need to change the port number in the config file if it matches Apple's existing usage.
Then find what psql installations exist
find /usr -type f -name psql
find /opt -type f -name psql
Try and figure out which one you need, perhaps add --version to help.
Then, let's see about editing your PATH. You must have some changes in your settings file anyway, so let's see if we can find where that setting is.
grep -l 'local/bin' ~/.*rc
That should list filenames containing local/bin - have a look and see if they are editing your PATH.

How do you update your "HOMEBREW_TEMP" environmental variable?

I'm getting the following error when running "brew doctor":
Error: Your Cellar and TEMP directories are on different volumes.
OS X won't move relative symlinks across volumes unless the target file already
exists. Brews known to be affected by this are Git and Narwhal.
You should set the "HOMEBREW_TEMP" environmental variable to a suitable
directory on the same volume as your Cellar
How do I set this variable? And what should I set it to? I can't seem to find anything about this when googling.
You set your HOMEBREW_TEMP by editing your ~/.bash_profile and doing this:
export HOMEBREW_TEMP=/new/path
Then start a new shell.
Alternatively type that into any already open shell.
Google setting shell environment variables for further information.
I fixed this problem by setting the path of the temp folder manualy.
First i created a folder temp in /usr/local/ and then added the following to my zsh file nano ~/.zshrc
export HOMEBREW_TEMP=/usr/local/temp
Same problem occurred to me. I actually have configured separate disk in memory for /private/tmp. Hope that's why this error occurred.
To solve this issue, create a directory somewhere, like /usr/local/brew_temp
Then add following line to file ~/.profile. If file doesn't exist create that file
export HOMEBREW_TEMP=/usr/local/brew_temp
In each restart it will set the HOMEBREW_TEMP environment variable to that path. After setting these option either you can restart OS X or run following in command line if you don't want to restart
. ~/.profile
For anyone that runs into this in the future, try restarting your computer and then running brew doctor again. That fixed it for me.

Resources