Category: Database

  • PostgreSQL – Check value is in array

    With PostgreSQL, if you have a field containing an Array and you want to get all the results containing this value in the array, you can use the following command. Here, we are looking for all the results in the table my_table containing my_value in the field my_array. SELECT * FROM my_table WHERE ‘my_value’=ANY(my_array) ORDER…

  • Calculate Database/Table size in MySQL

    MySQL is an open-source relational database management system (RDBMS) available under the terms of the GNU General Public License, as well as under a variety of proprietary agreements. Thanks to some few functions, it’s possible to retrieve important information about database size and/or table size for a MySQL instance. Size for all databases SELECT table_schema…

  • Increase display limit for a find in Mongo Shell

    When doing a find request on a Shell Mongo, the display is automatically paginated and you’re getting this: Type “it” for more By default, the number of rows returned is 20. But this value can easily be changed by using this command: DBQuery.shellBatchSize = 200; You will now have 200 rows displayed per page.

  • Manage permissions on MySQL for remote users

    MySQL has always been one of the most used database engine for websites. Its security is really important, isolating and managing access must be taken in consideration. Hereafter are some commands to perform some checking and some updates. I will consider those variables for my examples, but you should customize them with your own: Show…

  • Gather/Aggregate results with MongoDB

    Need to gather or aggregate some results with MongoDB? Easy! You can use the group command over any collection to get a nice display of your results aggregated: db.collection.group( { key: { document: 1}, cond: { }, reduce: function( curr, result ) { result.total += 1; }, initial: { total : 0 } } )…

  • Find PostgreSQL database size

    PostgreSQL is an object-relational database management system (ORDBMS). It’s a free and open-source tool available under BSD licence. Thanks to some built-in functions, you can get several information regarding database and/or table size. You will find below the main and most used examples. Database size (in octal) dbpg-# SELECT pg_database_size(‘db_1’); pg_database_size —————- 342733824 (1 line) Database size…