Postgres 9.0 File System level backup on Debian Jessie - postgresql

I'm on Debian 8.2.0 and trying to run a postgres server from a folder I received. Version is 9.0.18. Here is the command I issue:
./postgres -D /home/swapps/project/PostgreSQL/9.0/data/
but the cursor keeps blinking in the terminal. I'm not sure what is happening?
Thanks

Sounds like it's started, and log_min_messages is set to a high enough value that you don't see any output.
Using another terminal session connect to the server on the port it's running on. If you don't know that check the port value in the postgresql.conf inside the data directory.
Generally you should use pg_ctl -D blah -w start rather than postgres directly. See the manual.
Or, for long term use, set it up to run on startup via an init script.

Related

Start PostgreSQL server manually and set verbose mode to see all queries

Is there a verbosity mode to get the list of queries executed on a PostgreSQL server in a terminal console when postgresql server is started manually? If yes, how to use it?
I'm starting the PostgreSQL server this way on macos:
/Applications/Postgres.app/Contents/Versions/12/bin/postgres -D "/Users/me/Library/Application Support/Postgres/var-12" -p 5432
You can specify log_statement=all, either in postgresql.conf or on the bin/postgres command line with -c.

pg_hba.conf for Postgresql from Windows Anaconda

I've just installed Postgressql (9.5.4 vc14_0) and Psycopg2 (2.7.5 py36h74b6da3_0) and I'm trying to use them within my Anaconda environment on Windows 10.
Whenever I run psycopg2.connect("host=localhost user=postgres") in a python interpreter or just psql on the command line I get this error:
could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
I've looked at other Stackoverflow questions regarding this, some answers say to look into a pg_hba.conf file although I haven't be able to find any. Where can I find a pg_hba.conf file for my Postgresql in my Anaconda Environment for Windows? If I have to make one, what should go in it? I haven't seen another SO question that uses the same Postgresql-Anaconda-Windows setup that I'm using.
Also I've looked into services.msc but haven't seen a service regarding postgresql.
I just ran into this error as well. Similar to what you did, I followed the installation page, ran conda install -c anaconda postgresql and received the same error in your post.
I have used postgresql through direct installation before, in osx and as far as I can recall, you could just psql into the database once the installation is complete.
Maybe this isn't the case for anaconda installations. I overcame this by initializing a new database system in a new, empty folder. In my case, I created a new folder in "\AppData\Local\conda\"
-- Initialize the database system
pg_ctl init -D <path_to_your_database_system>
-- Start the database
C:/Users/kerwei/AppData/Local/Continuum/anaconda3/envs/py36/Library/bin/pg_ctl -D <path_to_your_database_system> -l logfile start
NOTE: After playing around with for awhile, I realized that once you exit the conda environment, the database instance gets terminated too - without properly shutting down. As I don't use it for production stuffs, it doesn't really bother me. However, further steps can be taken to include the database booting and shutting down during conda activate or conda deactivate to make it less cumbersome.

Unable to start sever, likely due to misplaced .conf. How do can I verify the cause and find/replace .conf?

I'm new to psql, and am having some issues that I think are being caused by a misplaced .conf file. When I tried to log into a database I created earlier I get an error
$ psql corporation
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
Based on the psql docs it looks like the server isn't running and ps confirms this. Since I don't remember having to start it last time I used psql I was a little confused, but it seemed easy to fix. Unfortunately, my attempts to start the sever have not worked. Using the first method suggested by the docs gets me
$ postgres -D /usr/local/pgsql/data
postgres cannot access the server configuration file "/usr/local/pgsql/data/postgresql.conf": No such file or directory
While the second method results in
$postgres -D /usr/local/pgsql/data >logfile 2>&1 &
[1] 3165
Ps confirms that neither of these methods started postgres, and when I tried to open the database anyway, to double check, it returns a slightly different error message than before.
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"?
[1]+ Exit 2 postgres -D /usr/local/pgsql/data > logfile 2>&
How to start PostgreSQL server on Mac OS X? seems related, but has some gaps. Just running initdb wasn't enough, and I don't seem to have a .conf.sample. Do I just need to create a new .conf from scratch or what?
For reference I'm running Snow Leopard, I originally tried to manually instal psql, but ended up installing brew then brew installing psql.
Have you tried doing a find?
sudo find / -name postgresql*

How to run postgres on centos when installed via YUM repo as default daemon user

With a freshly installed version of Postgres 9.2 via yum repository on Centos 6, how do you run postgres as a different user when it is configured to run as 'postgres:postgres' (u:g) out of the box?
In addition to AndrewPK's explanation, I'd like to note that you can also start new PostgreSQL instances as any user by stopping and disabling the system Pg service, then using:
initdb -D /path/to/data/directory
pg_ctl start -D /path/to/data/directory
This won't auto-start the server on boot, though. For that you must integrate into your init system. On CentOS 6 a simple System V-style init script in /etc/init.d/ and a suitable symlink into /etc/rc3.d/ or /etc/rc3.d/ (depending on default runlevel) is sufficient.
If running more than one instance at a time they must be on different ports. Change the port directive in postgresql.conf in the datadir or set it on startup with pg_ctl -o "-p 5433" .... You may also need to override the unix_socket_directories if your user doesn't have write permission to the default socket directory.
pg_ctl
initdb
This is only for a fresh installation (as it pertained to my situation) as it involves blowing away the data dir.
The steps I took to resolve this issue while utilizing the packaged startup scripts for a fresh installation:
Remove the postgres data dir /var/lib/pgsql/9.2/data if you've already gone through the initdb process with the postgres user:group configured as default.
Modify the startup script (/etc/init.d/postgresql-9.2) to replace all instances of postgres:postgres with NEWUSER:NEWGROUP.
Modify the startup script to replace all instances of postgres in any $SU -l postgres lines with the NEWUSER.
run /etc/init.d/postgres initdb to regenerate the cluster using the new username
Make sure any logs created are owned by the new user or remove old logs if error on initdb (the configuration file in my case was found in /var/lib/pgsql/9.2/data/postgresql.conf).
Startup postgres and it should now be running under the new user/group.
I understand this might not be what other people are looking for if they have existing postgres db's and want to restart the server to run as a different user/group combo - this was not my case, and I didn't see an answer posted anywhere for a 'fresh' install utilizing the pre-packaged startup scripts.

Display Postgres server logs output in terminal and record to logs at same time

I'm running Postgres 9.1 (Homebrew installation on Mac OSX) and I'd like to monitor my postgres server more closely.
My question relates to logs. I'd like to get the logs displaying in a terminal pane. Here's what the Postgres docs say about the logs:
"On Unix-like systems, by default, the server's standard output and standard error are sent to pg_ctl's standard output (not standard error). The standard output of pg_ctl should then be redirected to a file or piped to another process such as a log rotating program like rotatelogs; otherwise postgres will write its output to the controlling terminal (from the background) and will not leave the shell's process group. On Windows, by default the server's standard output and standard error are sent to the terminal. These default behaviors can be changed by using -l to append the server's output to a log file. Use of either -l or output redirection is recommended."
So, when I get my postgres server running with the following:
pg_ctl start -D /usr/local/var/postgres
The logs display in the terminal window. When I run:
pg_ctl start -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log
the logs go to my logfile and don't display in terminal.
In short, it would be great if anyone can tell me what command I use after I've directed logs to the file (with the second command) to make the logs also appear at the command line. It helps when I'm developing (in Django) to watch the SQL statements get executed in real time.
You could watch the log with the command:
tail -f /usr/local/var/postgres/server.log
I was able to find the logs in:
less /var/log/postgresql/postgresql-10-main.log
using ubuntu 18.04 with postgresql version: 10
For Centos7 and Postgress12
/var/lib/pgsql/12/data/log