Kill a postgresql session/connection

You can use pg_terminate_backend() to kill a connection. You have to be superuser to use this function. This works on all operating systems the same. SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE — don’t kill my own connection! pid <> pg_backend_pid() — don’t kill the connections to other databases AND datname=”database_name” ; Before executing this query, you … Read more

Maximum length for MySQL type text

See for maximum numbers: http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html TINYBLOB, TINYTEXT L + 1 bytes, where L < 2^8 (255 Bytes) BLOB, TEXT L + 2 bytes, where L < 2^16 (64 Kilobytes) MEDIUMBLOB, MEDIUMTEXT L + 3 bytes, where L < 2^24 (16 Megabytes) LONGBLOB, LONGTEXT L + 4 bytes, where L < 2^32 (4 Gigabytes) L is … Read more

How do you rename a MongoDB database?

You could do this, if you’re using MongoDB < 4.2 (ref): db.copyDatabase(“db_to_rename”,”db_renamed”,”localhost”) use db_to_rename db.dropDatabase(); Editorial Note: this is the same approach used in the question itself but has proven useful to others regardless.

How to shrink/purge ibdata1 file in MySQL

That ibdata1 isn’t shrinking is a particularly annoying feature of MySQL. The ibdata1 file can’t actually be shrunk unless you delete all databases, remove the files and reload a dump. But you can configure MySQL so that each table, including its indexes, is stored as a separate file. In that way ibdata1 will not grow … Read more

Elasticsearch query to return all records

I think lucene syntax is supported so: http://localhost:9200/foo/_search?pretty=true&q=*:* size defaults to 10, so you may also need &size=BIGNUMBER to get more than 10 items. (where BIGNUMBER equals a number you believe is bigger than your dataset) BUT, elasticsearch documentation suggests for large result sets, using the scan search type. EG: curl -XGET ‘localhost:9200/foo/_search?search_type=scan&scroll=10m&size=50’ -d ‘ … Read more

How do you query for “is not null” in Mongo?

This will return all documents with a key called “IMAGE URL”, but they may still have a null value. db.mycollection.find({“IMAGE URL”:{$exists:true}}); This will return all documents with both a key called “IMAGE URL” and a non-null value. db.mycollection.find({“IMAGE URL”:{$ne:null}}); Also, according to the docs, $exists currently can’t use an index, but $ne can. Edit: Adding … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)