How to handle postgresql connection problems - macos

I have run into a number of cases where the postgresql connection is in a bad state. OK, I'll make this complicated by having a master with a couple of slave servers... And to complicate matters even more, the master is on OS X with postgresql installed via homebrew
So things like
pg_basebackup: could not connect to server: could not connect to server: Connection refused
Is the server running on host "XX.XX.XX.XX" and accepting
TCP/IP connections on port 5432?
crop up. The master postgres/server.log was showing
FATAL: pre-existing shared memory block (key xx, ID yyy) is still in use.
this notwithstanding running
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
to start and stop the service. [head scratch] Got we worrying... So I run
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
I query the master's application and can edit data! WAIT postgresql was supposed to be unloaded!
So launctl is NOT working as expected... This explains why some synching up has fallen by the wayside.
Question 1: How can we ensure that postgres is really stopped on OS X because although it may be risky, the only alternative appears to be to kill the postmaster.pid
Then things went probably haywire in the flow... master's log states:
LOG: could not send data to client: Broken pipe
and effectively one of the VPS is complaining
$ service postgresql stop
Error: pid file is invalid, please manually kill the stale server process.
Question 2: how can those be killed (Ubuntu 14.04) without harming the database and the WAL process that should be updating the slave? (or is there a more effective/saner way of handling master-slave replication?)

Related

Cannot create Solr core on localhost - ERROR: Connection reset

I'm running Solr 8.2 on OSX 10.13.5. The Solr dashboard is accessible in my browser (via http://localhost:8983), yet when I run the terminal command "bin/solr create -c test" to create a core, after a few moments I end up with:
ERROR: Connection reset
I've tried booting Solr as sudo, and the result is the same. I'm at a bit of a loss here. How can I resolve this connection error and create a core? Thanks!
I figured this out. It turns out that port 8983 was still in TIME_WAIT mode. I obtained the port's PID with:
sudo lsof -i :8983
Then closed the port with:
kill PID
Where 'PID' is the numerical PID of the port. With the port now being free of traffic, the core creation worked just fine. I'm leaving this posted in case any other Solr beginners hit this snag!

How do I find and terminate a process listening to a port when I can't find it on my machine?

Attempting to kill port and locate possible process paths
I'm trying to use the Postgres.app to utilize the database, but keep running into the "Port in use" issue. I had originally brew installed postgres, but opted to use the app instead. So I brew removed postgres and installed Postgres.app. But now when I try to connect, it says that the port is in use. From everything that I've read, postgresql is the only process that listens at that port (I'm not using any other databases like MySQL). So, I was going to try to use the sudo launchctl unload -w /path_to/process command, but as you can see above...when I use which postgres or which postgresql, there's no path found. I also tried killing the connection to the port, but the ghost postgresql automatically connects right afterwards. Any tips on how to find out what the heck is listening on the port and prevent it from auto-connecting?
Edit: I tried using the Activity Monitor to see if I had accidentally installed a second version of the postgres.app. I checked to see what was the PID of the process listening in on the port. But it's not listed in the activity monitor. So I still have no idea how to find whatever is listening on the port
PID not listed in Activity monitor screen

Mongodb on Terminal keeps getting stuck

I have a Macbook Pro with El Capitan. I installed mongodb on my terminal with macports, which is similar to homebrew. I've followed all of the instructions and I've made sure to change the user permissions to /data/db. Does anyone have any idea of what's wrong with my mongodb installation?
Whenever I try to run "mongod", it keeps pausing at "waiting for connections on port 27017". This is shown in Screenshot 1. Then I hit CTRL-C to exit, and I get more error messages shown in Screenshot 2. Also the "mongo" command does not work either.
Here is the error report shown when entering "mongo".
MongoDB shell version: 3.0.8
connecting to: test
2016-01-11T19:08:41.888-0600 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
2016-01-11T19:08:41.890-0600 E QUERY Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:179:14)
at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed
Here is a link to my google drive with a photos of the error report for "mongod".
Screenshot 1 - https://drive.google.com/file/d/0Bwl_BDx-HIfcYnBJRUJfbzFvSm8/view?usp=sharing
Screenshot 2 - https://drive.google.com/file/d/0Bwl_BDx-HIfcdkVkUWJzeENuelU/view?usp=sharing
Whenever I try to run "mongod", it keeps pausing at "waiting for connections on port 27017".
This is exactly what it is supposed to do. Unless you indicate otherwise via a command switch (such as "--fork"), running "mongod" starts up the mongo server process within the current shell and blocks that shell until the process is terminated (via CTRL+C).
If you want to connect to the running mongo server process via the mongo shell, you'll need to open a second terminal to do so. From there, run "mongo" and it should connect to the server running in the first terminal shell.
Re-cap:
In terminal #1, run "mongod". When it says "waiting for connections...", it's ready to accept client connections. Do not stop the process via CTRL+C; do not close that terminal.
In terminal #2, run "mongo". It should connect to the server successfully.
This "connection refused" message is significant:
2016-01-11T19:08:41.888-0600 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
You need to work with the packet filter to flush all the rules. See this article near the bottom in order to open port 27017 which is what mongod uses:
http://www.macworld.co.uk/how-to/mac-software/how-open-specific-ports-in-os-x-1010-firewall-3616405/
This is quite direct:
https://gauravsohoni.wordpress.com/2015/04/14/mac-osx-open-port/
This may be less helpful but still worth glancing through:
https://support.apple.com/en-us/HT201642

Starting Postgres Server

I've had no luck in starting the postgres server. I can add new databases, tables, etc to the postgres from the terminal, but can't add things to the tables through a webpage. The webpage is running on a localhost for now.
The postgres data folder was originally created in a root user, but I moved it to my own user account and it solved many problems, but I'm back at the same old error I keep getting after entering postgres -D data (data being the data cluster folder)
EDT LOG: could not bind IPv4 socket: Address already in use
2015-06-18 11:11:35 EDT HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2015-06-18 11:11:35 EDT LOG: could not bind IPv6 socket: Address already in use
2015-06-18 11:11:35 EDT HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2015-06-18 11:11:35 EDT WARNING: could not create listen socket for "*"
2015-06-18 11:11:35 EDT FATAL: could not create any TCP/IP sockets
I tried two different commands to start the server.
pg_ctl -D data -l logfile start
which gave me this, but it's not correct
server starting
and
pg_ctl -D /Library/PostgreSQL/9.4/data -l log file start
which gave me this
LOG: skipping missing configuration file "/Library/PostgreSQL/9.4/data/postgresql.auto.conf"
pg_ctl: another server might be running; trying to start server anyway
server starting
The postgresql.auto.conf file is most definitely there with correct name and everything. If I try to stop the supposedly started server it results in this with the first one from the first command I tried and the second stop with the second command.
Is server running?
and
LOG: skipping missing configuration file "/Library/PostgreSQL/9.4/data/postgresql.auto.conf"
pg_ctl: could not send stop signal (PID: 83): Operation not permitted
Something seems to already use port 5432.
Try to find out, which program (maybe another instance of postgres) is blocking that port and decide whether to stop that other process, or not.
As an alternative reconfigure postgres to use other ports.
Maybe you can find out, what is blocking that port by typing this into the console:
lsof -n -i4TCP:5432 | grep LISTEN
Its clear that there is another instance of postgres running. You have to stop that one before starting yours manually as this will go in conflict with the port numbers.
sudo launchctl stop com.edb.launchd.postgresql-9.4
The try and launch with your command.

Installing Membase from source

I am trying to build and install membase from source tarball. The steps I followed are:
Un-archive the tar membase-server_src-1.7.1.1.tar.gz
Issue make (from within the untarred folder)
Once done, I enter into directory install/bin and invoke the script membase-server.
This starts up the server with a message:
The maximum number of open files for the membase user is set too low.
It must be at least 10240. Normally this can be increased by adding
the following lines to /etc/security/limits.conf:
Tried updating limits.conf as suggested, but no luck it continues to pop up the same message and continues booting
Given that the server is started I tried accessing memcached over port 11211, but I get a connection refused message. Then figured out (netstat) that memcached is listening to 11210 and tried telneting to port 11210, unfortunately the connection is closed as soon as I issue the following commands
stats
set myvar 0 0 5
Note: I am not getting any output from the commands above {Yes: stats did not show anything but still I issued set.}
Could somebody help me build and install membase from source? Also why is memcached listening to 11210 instead of 11211?
It would be great if somebody could also give me a step-by-step guide which I can follow to build from source from Git repository (I have not used autoconf earlier).
P.S: I have tried installing from binaries (debian package) on the same machines and I am able to successfully install and telnet. Hence not sure why is build from source not working.
You can increase the number of file descriptors on your machine by using the ulimit command. Try doing (you might need to use sudo as well):
ulimit -n 10240
I personally have this set in my .bash_rc so that whenever I start my terminal it is always set for me.
Also, memcached listens on port 11210 by default for Membase. This is done because Moxi, the memcached proxy server, listens on port 11211. I'm also pretty sure that the memcached version used for Membase only listens for the binary protocol so you won't be able to successfully telnet to 11210 and have commands work correctly. Telneting to 11211 (moxi) should work though.

Resources