Top Banner
1 PostgreSQL on Windows Magnus Hagander [email protected] PGCon, Ottawa May 2007
41

Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

Sep 15, 2018

Download

Documents

vonhi
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

1

PostgreSQL on Windows

Magnus [email protected]

PGCon, OttawaMay 2007

Page 2: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

2

� Why PostgreSQL on Windows� PostgreSQL for the Windows user� Windows for the PostgreSQL user� Advances in 8.3

Agenda

Page 3: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

3

Why PostgreSQL on Windows

� Isn’t Linux better?� Often, but not always

� Several scenarios� Developer laptops

� Desktop database� Migration scenarios

� Corporate policies

Page 4: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

4

� Why PostgreSQL on Windows� PostgreSQL for the Windows user� Windows for the PostgreSQL user� Advances in 8.3

Agenda

Page 5: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

5

PostgreSQL for the Windows user

� Unix inheritance� Multi-process, not multi-thread

� Shared memory� Requires ”modern” windows (2000+, no

FAT)

� Commandline!� psql, pg_dump, pg_dumpall, etc

� pgAdmin3 to the rescue!

Page 6: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

6

PostgreSQL for the Windows user

� Environment variables� Configuration files

� No registry� Edit with any text editor (e.g. notepad)� Edit with pgAdmin3

� Still just a textfile

� Signal server to reload (pause service)

� Security� Will not run with administrative privileges

Page 7: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

7

� Why PostgreSQL on Windows� PostgreSQL for the Windows user� Windows for the PostgreSQL user� Advances in 8.3

Agenda

Page 8: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

8

Windows for the PostgreSQL user

� It’s a brave new world� None of the normal tools

� No ps� No kill

� No top� No cron

� Nothing at all (almost)

� Builtin Windows tools are generally bad

Page 9: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

9

Architectural differences

� Runs as a service� Windows ”version” of daemon

� Started by ”Service Control Manager”� Has it’s own login and session

� Logs to a file or eventlog� Startup errors always to eventlog

� CreateProcess() instead of fork()� Extra important to use connection pooling

Page 10: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

10

Installing PostgreSQL

� Use the MSI� External languages need to be in PATH

� Perl, python, tcl etc� Path is per user or per system

� Or install from source� Complex, non-standard build environment

� 8.3 supports MSVC, but still complex

Page 11: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

11

Installing PostgreSQL - tips

� Turn off all unnecessary services� Install data on dedicated filesystem

� If possible, on dedicated spindles

� Use a junction or disk mount for xlog� Mount with ”noatime”

fsutil behavior set disablelastaccess 1

� Disable 8.3 filename generationfsutil behavior set disable8dot3 1

Page 12: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

12

Configuration parameters

� shared memory� Workload dependant

� Smaller is better?!

� fsync methods� open_datasync (o_direct in 8.3)� fsync_writethrough

� log_destination� lc_xyz

Page 13: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

13

Managing PostgreSQL

� Get the right tools!

http://www.microsoft.com/technet/sysinternals

� Process Explorer (the tool for Win32)� pstools

� Process monitor (debugging)� Junction (tablespaces, xlog location)

Page 14: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

14

Managing PostgreSQL

� Get the right tools!

http://www.microsoft.com/technet/sysinternals

� Process Explorer (the tool for Win32)� pstools

� Process monitor (debugging)� Junction (tablespaces, xlog location)

http://www.microsoft.com/technet/sysinternals

Page 15: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

15

Library dependencies

� On Unix: ”ldd”� On Windows ”depends”

� In the Windows Support Tools� Traverses all dependencies

Page 16: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

16

Process title

� Unix:

Page 17: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

17

Process title

� Win32:

Page 18: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

18

Process title

� Win32:

Page 19: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

19

Finding ”stuck processes”

� Unix:

Page 20: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

20

Finding ”stuck processes”

� Win32:

Page 21: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

21

Monitoring PostgreSQL

� Some things really didn’t change� pg_stat_xyz

� Has not changed at all

� PostgreSQL logs� pg_data\*.log� Don’t forget eventlog!

Page 22: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

22

Monitoring PostgreSQL

� Performance Monitor� Standard Windows monitoring still applies!

� Monitoring the whole server� Looking at individual backends� Looking at the whole cluster

Page 23: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

23

Monitoring PostgreSQL

� Performance Monitor� Standard Windows monitoring still applies!

� Monitoring the whole server� Looking at individual backends� Looking at the whole cluster

Page 24: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

24

Monitoring PostgreSQL

� Performance Monitor� Standard Windows monitoring still applies!

� Monitoring the whole server� Looking at individual backends� Looking at the whole cluster

Page 25: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

25

Monitoring PostgreSQL

� Performance Monitor� Standard Windows monitoring still applies!

� Monitoring the whole server� Looking at individual backends� Looking at the whole cluster

Page 26: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

26

Interesting counters to watch

� Number of processes� New process creations � Memory usage (private bytes, working

set)� Context switches / second� Processor queue length

Page 27: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

27

Interesting counters to watch

� I/O operations / second� I/O bytes / second� Physical disk queue length� Logical disk\avg sec / read or write

� xlog: <10ms

� data: <50ms

� Logical disk\Disk transfers / sec

Page 28: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

28

Monitoring with Process Explorer

� Add extra columns� Private bytes

� Local backend memory

� WS Shareable / WS Shared� Shared buffers + shared code

� Virtual Size� Just address space

� Context switch delta� Expensive on Windows!

Page 29: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

29

� Why PostgreSQL on Windows� PostgreSQL for the Windows user� Windows for the PostgreSQL user� Advances in 8.3

Agenda

Page 30: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

30

Advances in 8.3

� Main build is now built with Visual C++� More efficient binaries

� Works with Windows Debugger Tools� Works with Visual Studio debugger and

profiler� Support for detached symbols

Page 31: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

31

Windows debugger support in 8.3

� Debugger backtrace of mingw build

Page 32: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

32

Windows debugger support in 8.3

� Debugger backtrace of msvc build

Page 33: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

33

Windows debugger support in 8.3

� Debugger backtrace of msvc build

Page 34: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

34

Windows debugger support in 8.3

� Local symbols supported!

Page 35: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

35

Using windbg

� Step 0 – configure symbol directory

Page 36: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

36

Using windbg

� Step 1 – attach to running backend� Figured out pid using previous methods

Page 37: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

37

Using windbg

� Step 2 – watch it load

Page 38: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

38

Using windbg

� Step 3 – set a breakpoint

Page 39: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

39

Using windbg

� Step 4 – run and hit breakpoint

� Step 5 – load whatever views are needed

Page 40: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

40

Visual Studio debugger

� Much better actual debugger� Work off symbols or source tree� Suitable for development, not production

Page 41: Advanced PostgreSQL on Windows - Magnus Hagander PostgreSQL on Windows.pdf · 3 Why PostgreSQL on Windows Isn’t Linux better? Often, but not always Several scenarios Developer laptops

41

Thank you!

Questions?