środa, 9 czerwca 2010

Timestamp (0/2/4/8)

'Przedruk' z http://www.postgres.cz/index.php/PostgreSQL_SQL_Tricks

Dropping milliseconds from timestamp

Usually we don't need timestamp value in maximum precision. For mostly people only seconds are significant. Timestamp type allows to define precision - and we could to use this feature:
postgres=# select current_timestamp;
             now              
------------------------------
 2009-05-23 20:42:21.57899+02
(1 row)

Time: 196,784 ms
postgres=# select current_timestamp::timestamp(2);
          now           
------------------------
 2009-05-23 20:42:27.74
(1 row)

Time: 51,861 ms
postgres=# select current_timestamp::timestamp(0);
         now         
---------------------
 2009-05-23 20:42:31
(1 row)

Time: 0,729 ms

Binary casting

Bo zawsze zapominam, a już nie raz potrzebowałem...
...cytat z oficjalnej dokumentacji ...

Table 9.10. Bit String Operators
Operator Description Example Result
|| concatenation B'10001' || B'011' 10001011
& bitwise AND B'10001' & B'01101' 00001
| bitwise OR B'10001' | B'01101' 11101
# bitwise XOR B'10001' # B'01101' 11100
~ bitwise NOT ~ B'10001' 01110
<< bitwise shift left B'10001' << 3 01000
>> bitwise shift right B'10001' >> 2 00100

The following SQL-standard functions work on bit strings as well as character strings: length, bit_length, octet_length, position, substring.
In addition, it is possible to cast integral values to and from type bit. Some examples:
44::bit(10)                    0000101100
44::bit(3)                     100
cast(-44 as bit(12))           111111010100
'1110'::bit(4)::integer        14
Note that casting to just “bit” means casting to bit(1), and so it will deliver only the least significant bit of the integer.

VM Ware ESXi resource allocation

Zapisuję żeby pamiętać czego się spodziewać po odpowiednich ustawieniach
PostgreSQL Server 8.2 na VMWareESXi 4.x
- HDD  clustra PG - Mode Independent,Persistent (Changes are immediately and permanently written to the disk)
- Resource 
-- CPU =2 core 4522MHz +Shares=HIGH +Reservation=4522MHz +Limit=Unlimited
-- Memory 4096MB +Shares=HIGH +Reservation=4096MB +Limit=Unlimited

Dla ciężkiego selecta:
iostat -m -d /dev/sdb1 1  
Odczyt rzędu 45 - 100 MB
Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
sdb1            361,00        42,54         0,00         42          0
 iostat -x -d /dev/sdb1 2
Device:         rrqm/s   wrqm/s     r/s     w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sdb1            151,00     0,00  350,00    0,00 84816,00     0,00   242,33     1,05    2,94   2,14  74,80

Zapis DDL z EMS PostgreSQL Manager

1. Opis dla EMS 2010 ver 4.6.0.3
Zapis DDL wykonuj ZAWSZE w kodowaniu != UNICODE(USC-2) oraz UNICODE(UTF-8)

psql nie potrafi zinterpretować żadnego z nich!!!!

Dodanie set client_encoding = 'UNICODE' nie załatwia sprawy
2. Jedyną możliwością jest wybranie Charset 'cp1250(Windows CentralEuropean)
3. Można również skopiować do schowka (Ctrl+C), a następnie utworzenie pliku
- na windowsie edytory tworzą standardowo w kodowaniu ANSI (czyli win1250)
wówczas dla spokoju sumienia dodajemy na początku
set client_encoding = 'WIN1250'
----
Ewentualnie zapisujemy plik w UTF-8 (wybierając w edytorze) wówczas koniecznie musimy dodać
set client_encoding = 'UNICODE';

Ginekolog dr n. med. Piotr Siwek

Gabinet ginekologiczny specjalista ginekolog - położnik dr n. med. Piotr Siwek