Rails questions, SQL statement in logs - sql

So I am new to Rails, so pardon the basic question.
I see rails spits this out (in the console) for every request I make to my controller. Why? I'm not even doing any DB operation, I just started writing a HelloWorld rails app. I did pick mysql as the db when creating this rails project (rails -d mysql helloworld)
SQL (0.1ms) SET NAMES 'utf8'
SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
So I noticed, that rails attempts to establish a DB connection for every request, irrespective whether you do a DB/ActiveRecord operation. It does this right after it does action_controller/dispatch. This seems like a waste of DB resource to me, why establish a connection to DB when I may not even do a ActiveRecord operation??

You're seeing this on every request because you're in development mode. In production mode (or with class caching turned on), this only happens once, when the connection is added to the connection pool.

Related

Have problem connecting SQL server to Kafka via Debezium and don't result back in production server whereas test database works good

I have a problem with our production database.
CDC in activated in our MSSQL database, both in test and production. But as long as new records store in the test database we receive captured records in our Kafka topic but in the production area, there are no results.
I have a user in the production server with exact same config and properties with
which I have in the test server.
Both with public and db_datareader user mapping in login properties.
But there is a slight bit of differentiation when I execute the query
EXEC sp_cdc_help_change_data_capture
According to this Debezium documentation, I should get a result back showing
tables with corresponding CDC capture configurations. So, it returns mentioned result in the test database but I don't get back anything (empty result) in the production database.
Are there any additional settings that I should consider to get appropriate results?

Same database - different output from different clients

I have a docker container with Oracle DB which I try to access from different clients with same credentials and its behaviour is quite strange.
I have set up connection in IDEA with following JDBC URL: jdbc:oracle:thin:#//localhost:1526/XEPDB1
Also I work with it via Spring Data framework in another container, url is jdbc:oracle:thin:#oracle:1521/XEPDB1 (port is forwarded to outer world as 1526, container name is oracle)
And finally, I tried to access the db using sqlplus from within db host: sqlplus LOGIN/PASSWORD#localhost:1521/XEPDB1
All connections are successful, but simple inserts and selects for same table show that each client sees only it's own modifications. What is wrong? How do I share same table between clients?
According to the connection strings, all the users are connected to the same database, so that isn't the issue.
The issue is probably that each user that modifies the data (e.g., inserts new rows), does so without committing, and thus this data is only available in their current session. Once they commit the data, it will be available to all the other sessions too.

Cache MySQL connection in rails. NO activerecord

I'm working on a rails app with mongodb, mongoid as ORM. I am not using activerecord in this project. I do need however to connect to a couple of MySQL dbs to get and write some data. I have a total of 3 queries that I need to execute on these dbs.
I feel like for what I need to do, there's no reason to include activerecord as it would be overkill.
The problem is that every time I need to get data from the MySQL db, I need to open a new connection to the server and close it after a couple of seconds. These queries are frequent, every 5 seconds. Is there any way to store a MySQL connection and reuse that instead of closing and reopening? I find it to be less overhead. Also, I'd like to have a way to re-open a connection if for some reason it should close unexpectedly. I remember there was a fix some time ago about "MySQL server has gone away" error and I think this will happen if I don't use activerecord.

Rails: View ActiveRecord's resulting query

ActiveRecord's query interface seems for me sometimes very complex and not intuitive. Is there a possibility to view in which SQL query results Rails construction I have written?
If you look in the console with the web server running, you will see what the ActiveRecord queries are compiled into. Additionally, you can open up the Rails console (rails console) and inspect them manually.

Postgres Query Logging for Windows

I have an application which is based on a Postgres database and I need to be able to examine the requests the application sends of the database.
I want to have Postgres log all of the queries it receives somewhere that I can examine them in order to rebuild some of its functionality in another application.
Can someone recommend a simple way to logging the queries Postgres receives in a Windows operating system?
Thanks,
Craig
Edit your postgresql.conf for PostgreSQL server, and either change log_statement to 'all' or change log_min_duration_statement to 0.
After the change you have to reload PostgreSQL configuration, and the queries will be logged to PostgreSQL log.