MongoDB connection abnormal increase - mongodb

I use mongodb client to connect Database like here. Notice, i only use one connect to DB, but when i start my application and check Mongodb connection by command.
db.serverStatus().connections
Before start app at 8 connection, after it increase more 20 connection. I miss something, any one help me to explain ?

Related

Heroku Postgres filling up connections without any use

I have a Heroku Postgres DB(free tier) that's connected to my backend API for testing purposes. Today I tried accessing the database and I kept getting an error "too many connections for Role 'role'". Please note that I've not connected to this API today and for some reason, all 20 connections have been used up.
I can't even connect to the DB through PgAdmin to even try and kill some of the connections as I get the same error there.
Any help please?

Regarding Heroku Postgres limit of 20 connections, if I close pgadmin will I have to waste another connection?

I connected to my team's Heroku Postgres database through pgAdmin 4, using up 1 out of the 20 connections limit. If I stop the pgAdmin server, will I have to reconnect later when I need it and waste another connection? I'm new to backend and just an intern so I don't want to mess anything up. Thanks for the help

not able to connect postgresql after 30 connections

I have 2 cloud servers of postgresql, 1st one is working fine but in second after 30 mins i am not able to connect from java application. When i connect from pgadmin it shows 30 to 40 connection and after killing those connection every thing runs smooth.
its
configuration:
postgresql/9.3
max_connections = 100
shared_buffers = 4GB
When same application is connect to other postgresql with same schema every thing works fine forever
Configuration:
postgresql/9.1
max_connections = 100
shared_buffers = 32MB
Can u please help me to understand or fix the issue
I work on a PostgreSQL 9.3 instance with hundreds of open connections. I concur to you that the open connections themselves shouldn't be a problem. Sine we don't have much information, what follows is a description of how to get started troubleshooting.
Check server logs for anything wrong. Maybe there is an issue on the OS level with initiating connections?
Try logging in with psql as the application user. Does the problem persist? If not, the problem is not with PostgreSQL. I would take a closer look at the Java code and see if something is happening there.
Note that psql and other libpq actions may not give you the full picture. Try connecting locally over a non-SSL connection while watching a packet capture. You can find (and look up) the SQLSTATE error of the connection in this case. This is because, for legacy and backwards compatibility reasons libpq does not pass the sqlstate up to the client app when connecting to the database.
My bet though is that this is not a postgresql issue. It may be an operating system issue. It may be a resource issue. It may be a client application issue.

Mongo DB logs showing hundreds of open connections without any running operations

When I check my MongoDB logs (/var/log/mongodb/mongodb.log), it shows something like:
end connection 127.0.0.1:57132 (**651 connections now open**)
But I am not running so many processes. How are so many connections open? Is there a way to close all these connections?
I do run a cron job (from shell script) to query mongodb every minute. Is that what is causing so many open connections? Should I close the connection every time after querying?
When I run db.serverStatus().connections, I get:
{ "current" : 500, "available" : 319, "totalCreated" : NumberLong(1328754) }
I think that's too big a number. How do I handle this?
Mongo does not usually log information about connections unless they are somehow exceptional (in size of the results or time to perform them for instance). Is this a cluster? If so these connections are probably the normal result of the mongo boxes syncing to each other. If not try
netstat -ln|grep 27017
to see who's using your mongo.
Two reasons I have seen for high connection counts:
When using replication
The Java driver didn't close any connections one it had opened them. Could be controlled with a property

How to check application is reading from Secondary Node in MongodB?

I have a 3 member replica set. Read preference is set as "Secondary Preferred" How to check application is reading from Secondary Node in MongodB? Please suggest.
Firstly you can configure profiling. For that you need to start your mongodb servers with option --profile 2 and configure log file. It'll log all queries.
After that you can read log for each instance db. Simple example:
db.your_collection.profile.find({ns: "name_your_db.your_collection"})
Secondly you can use mongotop. You need to start it for each mongodb server.
For example:
mongotop -h server_ip:server_port seconds
mongotop -h 127.0.0.1:27017 5
It'll print every specified period of time log, where you can read how much time for read or write is taken for each collection.
Other means of determining whether queries are sent to secondaries:
Enable command logging in the driver, which should tell you which server each command was sent to.
Inspect server logs for connections being made or not made, then set minimum connection pool size to 0 so that a connection is only made when needed for a query, then run some queries.