background preloader

Databases

Facebook Twitter

Performance - Measure the size of a PostgreSQL table row. Q2: way to measure page size PostgreSQL provides a number of Database Object Size Functions, you can use.

performance - Measure the size of a PostgreSQL table row

I packed the most interesting ones in this query and added some Statistics Access Functions. This is going to demonstrate that the various methods to measure the "size of a row" can lead to very different results. It all depends what you want to measure exactly. Replace public.tbl with your (optionally schema-qualified) table name to get a compact view of collected statistics about the size of your rows. I only pack the values in arrays and unnest() again, so I don't have to spell out calculations for every single row repeatedly.

General row count statistics are appended at the end with unconventional SQL-foo to get everything in one query. Result: PostgreSQL. Introduction PostgreSQL is a powerful object-relational database management system, provided under a flexible BSD-style license.[1] PostgreSQL contains many advanced features, is very fast and standards compliant.

PostgreSQL

PostgreSQL has bindings for many programming languages such as C, C++, Python, Java, PHP, Ruby... It can be used to power anything from simple web applications to massive databases with millions of records. Client Installation If you only wish to connect to an external PostgreSQL server, do not install the main PostgreSQL package, but install the PostgreSQL client package instead. Sudo apt-get install postgresql-client you then connect to the server with the following command.

How To Install and Use PostgreSQL on Ubuntu 14.04. Introduction Relational database management systems are a key component of many web sites and applications.

How To Install and Use PostgreSQL on Ubuntu 14.04

They provide a structured way to store, organize, and access information. PostgreSQL, or Postgres, is a relational database management system that provides an implementation of the SQL querying language. It is a popular choice for many small and large projects and has the advantage of being standards-compliant and having many advanced features like reliable transactions and concurrency without read locks. In this guide, we will demonstrate how to install Postgres on an Ubuntu 14.04 VPS instance and go over some basic ways to use it.

Installation Ubuntu's default repositories contain Postgres packages, so we can install them without a hassle using the apt packaging system. Since we haven't updated our local apt repository lately, let's do that now. Sudo apt-get update sudo apt-get install postgresql postgresql-contrib Using PostgreSQL Roles and Databases sudo -i -u postgres psql \q \conninfo. Creating a copy of a database in PostgreSQL. What can you do with PostgreSQL and JSON? PostgreSQL 9.2 added a native JSON data type, but didn’t add much else.

What can you do with PostgreSQL and JSON?

You’ve got three options if you actually want to do something with it: Wait for PostgreSQL 9.3 (or use the beta) Use the plv8 extension. Valid option, but more DIY (you’ll have to define your own functions) Use the json_enhancements extension, which backports the new JSON functionality in 9.3 to 9.2. HOWTO use JSON functionality in PostgreSQL - Stormatics. In a previous post, I talked about the excitement that surrounds NoSQL support in PostgreSQL.

HOWTO use JSON functionality in PostgreSQL - Stormatics

Today, I will dive a little deeper into the technical details of native JSON support that makes NoSQL possible. Below, I explain how to use some basic functions and operators. Creating a table with JSON column So this is fairly simple. You can declare a JSON column just like a column of any other data type. Json_sample=# CREATE TABLE sales (id INT, sale JSON); CREATE TABLE Inserting JSON data Insertion of data is pretty close to that of any other data type as well, except that you have to make sure the data is in a valid JSON format. John bought 4 cartons of milk: Susan bought 2 loaves of bread: Mark bought a dozen bananas: Jane bought a pack of cereal: Retrieving JSON data Like insertion, retrieving the JSON formatted data is fairly straightforward as well.

Json_sample=# SELECT * FROM sales; id | sale Retrieving JSONs – The ‘->’ and ‘->>’ operators Now comes the real fun part! Postgres Datatypes – The ones you're not using. Craig Kerstiens. Postgres has a variety of datatypes, in fact quite a few more than most other databases.

Postgres Datatypes – The ones you're not using. Craig Kerstiens

Most commonly applications take advantage of the standard ones – integers, text, numeric, etc. Almost every application needs these basic types, the rarer ones may be needed less frequently. And while not needed on every application when you do need them they can be an extremely handy. So without further ado let’s look at some of these rarer but awesome types. hstore Yes, I’ve talked about this one before, yet still not enough people are using it. It’s of note that hstore is an extension and not enabled by default. Range types If there is ever a time where you have two columns in your database with one being a from, another being a to, you probably want to be using range types. Timestamp with Timezone Timestamps are annoying, plain and simple. Integers are primary keys aren’t great. Similar to hstore, there’s an extension that makes the UUID much more useful.