文档库 最新最全的文档下载
当前位置:文档库 › stm8L051F3

stm8L051F3

stm8L051F3
stm8L051F3

This is information on a product in full production.

March 2014

DocID023465 Rev 21/93

STM8L051F3

Value Line, 8-bit ultralow power MCU, 8-KB Flash,

256-byte data EEPROM, RTC, timers, USART, I2C, SPI, ADC

Datasheet production data

Features

?Operating conditions

–Operating power supply: 1.8 V to 3.6 V Temperature range: ?40 °C to 85 °C ?Low power features

– 5 low power modes: Wait, Low power run (5.1 μA), Low power wait (3 μA), Active-halt with RTC (1.3 μA), Halt (350 nA)–Ultra-low leakage per I/0: 50 nA –Fast wakeup from Halt: 5 μs ?Advanced STM8 core

–Harvard architecture and 3-stage pipeline –Max freq: 16 MHz, 16 CISC MIPS peak –Up to 40 external interrupt sources ?Reset and supply management

–Low power, ultra-safe BOR reset with 5 selectable thresholds

–Ultra low power POR/PDR

–Programmable voltage detector (PVD)?Clock management

–32 kHz and 1 to 16 MHz crystal oscillators –Internal 16 MHz factory-trimmed RC –Internal 38 kHz low consumption RC –Clock security system ?Low power RTC

–BCD calendar with alarm interrupt

–Digital calibration with +/- 0.5 ppm accuracy –LSE security system

–Auto-wakeup from Halt w/ periodic interrupt ?Memories

–8 Kbytes of Flash program memory and 256 bytes of data EEPROM with ECC –Flexible write and read protection modes – 1 Kbyte of RAM

?DMA

– 4 channels supporting ADC, SPI, I2C, USART, timers

– 1 channel for memory-to-memory ?12-bit ADC up to 1 Msps/28 channels –Internal reference voltage

?Timers

–Two 16-bit timers with 2 channels (used as IC, OC, PWM), quadrature encoder –One 8-bit timer with 7-bit prescaler

– 2 watchdogs: 1 Window, 1 Independent –Beeper timer with 1, 2 or 4 kHz frequencies ?Communication interfaces

–Synchronous serial interface (SPI)–Fast I 2C 400 kHz SMBus and PMBus –USART ?Up to 18 I/Os, all mappable on interrupt vectors ?Development support

–Fast on-chip programming and non-intrusive debugging with SWIM –Bootloader using USART

https://www.wendangku.net/doc/db2763742.html,

Contents STM8L051F3

Contents

1Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

2Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.1Device overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2.2Ultra low power continuum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11

3Functional overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

3.1Low power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

3.2Central processing unit STM8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

3.2.1Advanced STM8 Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

3.2.2Interrupt controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

3.3Reset and supply management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

3.3.1Power supply scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

3.3.2Power supply supervisor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

3.3.3Voltage regulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

3.4Clock management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

3.5Low power real-time clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

3.6Memories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

3.7DMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

3.8Analog-to-digital converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

3.9System configuration controller and routing interface . . . . . . . . . . . . . . . 19

3.10Timers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

3.10.116-bit general purpose timers (TIM2, TIM3) . . . . . . . . . . . . . . . . . . . . . 19

3.10.28-bit basic timer (TIM4) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

3.11Watchdog timers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

3.11.1Window watchdog timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3.11.2Independent watchdog timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3.12Beeper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3.13Communication interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3.13.1SPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3.13.2I2C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3.13.3USART . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

3.14Infrared (IR) interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2/93DocID023465 Rev 2

STM8L051F3Contents

3.15Development support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

4Pin description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

4.1System configuration options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

5Memory and register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

5.1Memory mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

5.2Register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 6Interrupt vector mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 7Option bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

8Electrical parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

8.1Parameter conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

8.1.1Minimum and maximum values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

8.1.2Typical values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

8.1.3Typical curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

8.1.4Loading capacitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

8.1.5Pin input voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

8.2Absolute maximum ratings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

8.3Operating conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

8.3.1General operating conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

8.3.2Embedded reset and power control block characteristics . . . . . . . . . . . 49

8.3.3Supply current characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

8.3.4Clock and timing characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

8.3.5Memory characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

8.3.6I/O current injection characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

8.3.7I/O port pin characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

8.3.8Communication interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

8.3.9Embedded reference voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

8.3.1012-bit ADC1 characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

8.3.11EMC characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

9Package characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

9.1ECOPACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

9.2Package mechanical data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

DocID023465 Rev 23/93

Contents STM8L051F3

9.2.120-lead thin shrink small package (TSSOP20) . . . . . . . . . . . . . . . . . . . 89

9.3Thermal characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 10Device ordering information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 11Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

4/93DocID023465 Rev 2

STM8L051F3List of tables List of tables

Table 1.Low density value line STM8L05xxx low power device features and peripheral counts. . . 10 Table 2.Timer feature comparison. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Table 3.Legend/abbreviation for Table4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Table 4.Low density value line STM8L05xxx pin description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Table 5.Flash and RAM boundary addresses. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Table 6.I/O port hardware register map. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Table 7.General hardware register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Table 8.CPU/SWIM/debug module/interrupt controller registers. . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Table 9.Interrupt mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Table 10.Option byte addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Table 11.Option byte description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Table 12.Voltage characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Table 13.Current characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Table 14.Thermal characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Table 15.General operating conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Table 16.Embedded reset and power control block characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . 49 Table 17.Total current consumption in Run mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Table 18.Total current consumption in Wait mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Table 19.Total current consumption and timing in Low power run mode at VDD = 1.8V to

3.6V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Table 20.Total current consumption in Low power wait mode at VDD = 1.8V to 3.6V . . . . . . . . . . 56 Table 21.Total current consumption and timing in Active-halt mode at VDD = 1.8V to 3.6V. . . . . . 57 Table 22.Typical current consumption in Active-halt mode, RTC clocked by LSE external crystal. . 57 Table 23.Total current consumption and timing in Halt mode at VDD = 1.8 to 3.6 V . . . . . . . . . . . . 58 Table 2

4.Peripheral current consumption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Table 2

5.Current consumption under external reset. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Table 2

6.HSE external clock characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Table 2

7.LSE external clock characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Table 2

8.HSE oscillator characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Table 2

9.LSE oscillator characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Table 30.HSI oscillator characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Table 31.LSI oscillator characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Table 32.RAM and hardware registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Table 33.Flash program and data EEPROM memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Table 34.I/O current injection susceptibility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Table 35.I/O static characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Table 36.Output driving current (high sink ports). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Table 37.Output driving current (true open drain ports). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Table 38.Output driving current (PA0 with high sink LED driver capability). . . . . . . . . . . . . . . . . . . . 70 Table 39.NRST pin characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Table 40.SPI1 characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Table 41.I2C characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Table 42.Reference voltage characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Table 43.ADC1 characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Table 44.ADC1 accuracy with VDDA = 3.3 V to 2.5 V. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Table 45.ADC1 accuracy with VDDA = 2.4 V to 3.6 V. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Table 46.ADC1 accuracy with VDDA = VREF+ = 1.8 V to 2.4 V. . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Table 47.R AIN max for f ADC = 16 MHz. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

DocID023465 Rev 25/93

List of tables STM8L051F3 Table 48.EMS data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Table 49.EMI data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Table 50.ESD absolute maximum ratings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Table 51.Electrical sensitivities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Table 52.TSSOP20 20-lead thin shrink small package, mechanical data. . . . . . . . . . . . . . . . . . . . . 89 Table 53.Thermal characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Table 54.Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

6/93DocID023465 Rev 2

STM8L051F3List of figures List of figures

Figure 1.Low density value line STM8L05xxx device block diagram. . . . . . . . . . . . . . . . . . . . . . . . 12 Figure 2.Low density value line STM8L05xxx clock tree diagram . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Figure 3.STM8L051F3 20-pin TSSOP20 package pinout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Figure 4.Memory map. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Figure 5.Pin loading conditions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Figure 6.Pin input voltage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Figure 7.POR/BOR thresholds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Figure 8.Typ. IDD(RUN) vs. VDD,fCPU= 16MHz. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Figure 9.Typ. IDD(Wait) vs. VDD,fCPU=16MHz 1). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Figure 10.Typ. IDD(LPR) vs. VDD (LSI clock source) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Figure 11.Typ. IDD(LPW) vs. VDD (LSI clock source) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Figure 12.HSE oscillator circuit diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Figure 13.LSE oscillator circuit diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Figure 14.Typical HSI frequency vs V DD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Figure 15.Typical LSI frequency vs. VDD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Figure 16.Typical VIL and VIH vs VDD (high sink I/Os) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Figure 17.Typical VIL and VIH vs VDD (true open drain I/Os) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Figure 18.Typical pull-up resistance R PU vs V DD with VIN=VSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Figure 19.Typical pull-up current I pu vs V DD with VIN=VSS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Figure 20.Typ. VOL @ VDD = 3.0 V (high sink ports) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Figure 21.Typ. VOL @ VDD = 1.8 V (high sink ports) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Figure 22.Typ. VOL @ VDD = 3.0 V (true open drain ports) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Figure 23.Typ. VOL @ VDD = 1.8 V (true open drain ports) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Figure 24.Typ. VDD - VOH @ VDD = 3.0 V (high sink ports). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Figure 25.Typ. VDD - VOH @ VDD = 1.8 V (high sink ports). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Figure 26.Typical NRST pull-up resistance R PU vs V DD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Figure 27.Typical NRST pull-up current I pu vs V DD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Figure 28.Recommended NRST pin configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Figure 29.SPI1 timing diagram - slave mode and CPHA=0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Figure 30.SPI1 timing diagram - slave mode and CPHA=1(1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Figure 31.SPI1 timing diagram - master mode(1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Figure 32.Typical application with I2C bus and timing diagram 1) . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Figure 33.ADC1 accuracy characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Figure 34.Typical connection diagram using the ADC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Figure 35.Maximum dynamic current consumption on V REF+ supply pin during ADC

conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 Figure 36.Power supply and reference decoupling (V REF+ not connected to V DDA). . . . . . . . . . . . . . 85 Figure 37.Power supply and reference decoupling (VREF+ connected to VDDA). . . . . . . . . . . . . . . 85 Figure 38.TSSOP20 20-lead thin shrink small package outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Figure 39.TSSOP20 recommended footprint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Figure 40.Low density value line STM8L051F3 ordering information scheme. . . . . . . . . . . . . . . . . . 91

DocID023465 Rev 27/93

Introduction STM8L051F3 1 Introduction

This document describes the features, pinout, mechanical data and ordering information for

the low density value line STM8L051F3 microcontroller with 8-Kbyte Flash memory density.

For further details on the whole STMicroelectronics low density family please refer to

Section 2.2: Ultra low power continuum.

For detailed information on device operation and registers, refer to the reference manual

(RM0031).

For information on to the Flash program memory and data EEPROM, refer to the

programming manual (PM0054).

For information on the debug module and SWIM (single wire interface module), refer to the

STM8 SWIM communication protocol and debug module user manual (UM0470).

For information on the STM8 core, refer to the STM8 CPU programming manual (PM0044).

Low density value line devices provide the following benefits:

?Integrated system

–8 Kbytes of low-density embedded Flash program memory

–256 bytes of data EEPROM

– 1 Kbyte of RAM

–Internal high-speed and low-power low speed RC

–Embedded reset

?Ultra low power consumption

– 1 μA in Active-halt mode

–Clock gated system and optimized power management

–Capability to execute from RAM for Low power wait mode and Low power run

mode

?Advanced features

–Up to 16 MIPS at 16 MHz CPU clock frequency

–Direct memory access (DMA) for memory-to-memory or peripheral-to-memory access

?Short development cycles

–Application scalability across a common family product architecture with

compatible pinout, memory map and modular peripherals

–Wide choice of development tools

These features make the value line STM8L05xxx ultra low power microcontroller family

suitable for a wide range of consumer and mass market applications.

Refer to Table 1: Low density value line STM8L05xxx low power device features and

peripheral counts and Section 3: Functional overview for an overview of the complete range

of peripherals proposed in this family.

Figure 1 shows the block diagram of the low density value line STM8L05xxx family.

8/93DocID023465 Rev 2

STM8L051F3Description 2 Description

The low density value line STM8L05xxx devices are members of the STM8L ultra low power

8-bit family.

The value line STM8L05xxx ultra low power family features an enhanced STM8 CPU core

providing increased processing power (up to 16 MIPS at 16 MHz) while maintaining the

advantages of a CISC architecture with improved code density, a 24-bit linear addressing

space and an optimized architecture for low power operations.

The family includes an integrated debug module with a hardware interface (SWIM) which

allows non-intrusive In-Application debugging and ultra-fast Flash programming.

Low density value line STM8L05xxx microcontrollers feature embedded data EEPROM and

low power,low-voltage, single-supply program Flash memory.

The devices incorporate an extensive range of enhanced I/Os and peripherals, a 12-bit

ADC, a real-time clock, two 16-bit timers, one 8-bit timer, as well as standard

communication interfaces such as an SPI, an I2C interface, and one USART.

The modular design of the peripheral set allows the same peripherals to be found in

different ST microcontroller families including 32-bit families. This makes any transition to a

different family very easy, and simplified even more by the use of a common set of

development tools.

All value line STM8L ultra low power products are based on the same architecture with the

same memory mapping and a coherent pinout.

DocID023465 Rev 29/93

Description STM8L051F3

10/93DocID023465 Rev 2

2.1 Device overview

Table 1. Low density value line STM8L05xxx low power device features and

peripheral counts

Features

STM8L051F3

Flash (Kbytes)8Data EEPROM (Bytes)256RAM (Kbytes)

1

Timers

Basic

1(8-bit)General purpose 2(16-bit) Communicati

on interfaces

SPI

1I2C

1USART 1GPIOs

18 (1)1.The number of GPIOs given in this table includes the NRST/PA1 pin but the application can use the

NRST/PA1 pin as general purpose output only (PA1).

12-bit synchronized ADC (number of channels) 1 (10)

Others RTC, window watchdog, independent watchdog,

16-MHz and 32-kHz internal RC,

1- to 16-MHz and 32-kHz external oscillator

CPU frequency 16 MHz Operating voltage 1.8 to 3.6 V

Operating temperature ? 40 to +85 °C

Package

TSSOP20

STM8L051F3Description

2.2 Ultra low power continuum

The ultra low power value line STM8L05xxx and STM8L15xxx are fully pin-to-pin, software

and feature compatible. Besides the full compatibility within the STM8L family, the devices

are part of STMicroelectronics microcontrollers ultra low power strategy which also includes

STM8L101xx and STM32L15xxx. The STM8L and STM32L families allow a continuum of

performance, peripherals, system architecture, and features.

They are all based on STMicroelectronics 0.13 μm ultra-low leakage process.

Note:1The STM8L05xxx are pin-to-pin compatible with STM8L101xx devices.

2The STM32L family is pin-to-pin compatible with the general purpose STM32F family.

Please refer to STM32L15x documentation for more information on these devices.

Performance

All families incorporate highly energy-efficient cores with both Harvard architecture and

pipelined execution: advanced STM8 core for STM8L families and ARM? 32-bit Cortex?-M3

core for STM32L family. In addition specific care for the design architecture has been taken

to optimize the mA/DMIPS and mA/MHz ratios.

This allows the ultra low power performance to range from 5 up to 33.3 DMIPs.

Shared peripherals

STM8L05xx, STM8L15xx and STM32L15xx share identical peripherals which ensure a very

easy migration from one family to another:

?Analog peripheral: ADC1

?Digital peripherals: RTC and some communication interfaces

Common system strategy

To offer flexibility and optimize performance, the STM8L and STM32L devices use a

common architecture:

?Same power supply range from 1.8 to 3.6 V

?Architecture optimized to reach ultra low consumption both in low power modes and Run mode

?Fast startup strategy from low power modes

?Flexible system clock

?Ultra-safe reset: same reset strategy for both STM8L and STM32L including power-on reset, power-down reset, brownout reset and programmable voltage detector.

Features

ST ultra low power continuum also lies in feature compatibility:

?More than 10 packages with pin count from 20 to 100 pins and size down to 3 x 3 mm

?Memory density ranging from 4 to 128 Kbytes

DocID023465 Rev 211/93

Functional overview STM8L051F3

12/93DocID023465 Rev 2

3 Functional overview

1.Legend :

ADC: Analog-to-digital converter BOR: Brownout reset

DMA: Direct memory access

I2C: Inter-integrated circuit multimaster interface IWDG: Independent watchdog

POR/PDR: Power-on reset / power-down reset RTC: Real-time clock

SPI: Serial peripheral interface

SWIM: Single wire interface module

USART: Universal synchronous asynchronous receiver transmitter WWDG: Window watchdog

STM8L051F3Functional overview

3.1 Low power modes

The low density value line STM8L05xxx devices support five low power modes to achieve

the best compromise between low power consumption, short startup time and available

wakeup sources:

?Wait mode: The CPU clock is stopped, but selected peripherals keep running. An internal or external interrupt or a Reset can be used to exit the microcontroller from

Wait mode (WFE or WFI mode).

?Low power run mode: The CPU and the selected peripherals are running. Execution is done from RAM with a low speed oscillator (LSI or LSE). Flash memory and data

EEPROM are stopped and the voltage regulator is configured in ultra low power mode.

The microcontroller enters Low power run mode by software and can exit from this

mode by software or by a reset.

All interrupts must be masked. They cannot be used to exit the microcontroller from this

mode.

?Low power wait mode: This mode is entered when executing a Wait for event in Low power run mode. It is similar to Low power run mode except that the CPU clock is

stopped. The wakeup from this mode is triggered by a Reset or by an internal or

external event (peripheral event generated by the timers, serial interfaces, DMA

controller (DMA1) and I/O ports). When the wakeup is triggered by an event, the

system goes back to Low power run mode.

All interrupts must be masked. They cannot be used to exit the microcontroller from this

mode.

?Active-halt mode: CPU and peripheral clocks are stopped, except RTC. The wakeup can be triggered by RTC interrupts, external interrupts or reset.

?Halt mode: CPU and peripheral clocks are stopped, the device remains powered on.

The RAM content is preserved. The wakeup is triggered by an external interrupt or

reset. A few peripherals have also a wakeup from Halt capability. Switching off the

internal reference voltage reduces power consumption. Through software configuration

it is also possible to wake up the device without waiting for the internal reference

voltage wakeup time to have a fast wakeup time of 5 μs.

DocID023465 Rev 213/93

Functional overview STM8L051F3

14/93DocID023465 Rev 2

3.2 Central processing unit STM8

3.2.1 Advanced STM8 Core

The 8-bit STM8 core is designed for code efficiency and performance with an Harvard

architecture and a 3-stage pipeline.

It contains 6 internal registers which are directly addressable in each execution context, 20 addressing modes including indexed indirect and relative addressing, and 80 instructions.

Architecture and registers

?Harvard architecture ?3-stage pipeline

?32-bit wide program memory bus - single cycle fetching most instructions

?X and Y 16-bit index registers - enabling indexed addressing modes with or without offset and read-modify-write type data manipulations ?8-bit accumulator

?24-bit program counter - 16-Mbyte linear memory space ?16-bit stack pointer - access to a 64-Kbyte level stack

?

8-bit condition code register - 7 condition flags for the result of the last instruction

Addressing

?20 addressing modes

?Indexed indirect addressing mode for lookup tables located anywhere in the address space

?

Stack pointer relative addressing mode for local variables and parameter passing

Instruction set

?80 instructions with 2-byte average instruction size ?Standard data movement and logic/arithmetic functions ?8-bit by 8-bit multiplication

?16-bit by 8-bit and 16-bit by 16-bit division ?Bit manipulation

?Data transfer between stack and accumulator (push/pop) with direct stack access ?

Data transfer using the X and Y registers or direct memory-to-memory transfers

3.2.2 Interrupt controller

The low density value line STM8L05xxx features a nested vectored interrupt controller:?Nested interrupts with 3 software priority levels ?32 interrupt vectors with hardware priority ?Up to 17 external interrupt sources on 11 vectors ?

Trap and reset interrupts

STM8L051F3Functional overview 3.3 Reset and supply management

3.3.1 Power supply scheme

The device requires a 1.8 V to 3.6 V operating supply voltage (V DD). The external power

supply pins must be connected as follows:

?V SS1; V DD1 = 1.8 to 3.6 V: external power supply for I/Os and for the internal regulator.

Provided externally through V DD1 pins, the corresponding ground pin is V SS1.

?V SSA; V DDA = 1.8 to 3.6 V: external power supplies for analog peripherals. V DDA and V SSA must be connected to V DD1 and V SS1, respectively.

?V SS2; V DD2 = 1.8 to 3.6 V: external power supplies for I/Os. V DD2 and V SS2 must be connected to V DD1 and V SS1, respectively.

?V REF+, V REF- (for ADC1): external reference voltage for ADC1. Must be provided externally through V REF+ and V REF- pin.

3.3.2 Power supply supervisor

The device has an integrated ZEROPOWER power-on reset (POR)/power-down reset

(PDR), coupled with a brownout reset (BOR) circuitry. When the microcontroller operates

between 1.8 and 3.6 V, BOR is always active and ensures proper operation starting from

1.8 V. After the 1.8 V BOR threshold is reached, the option byte loading process starts,

either to confirm or modify default thresholds, or to disable BOR permanently.

Five BOR thresholds are available through option bytes, starting from 1.8 V to 3 V. To

reduce the power consumption in Halt mode, it is possible to automatically switch off the

internal reference voltage (and consequently the BOR) in Halt mode. The device remains in

reset state when V DD is below a specified threshold, V POR/PDR or V BOR, without the need for

any external reset circuit.

The device features an embedded programmable voltage detector (PVD) that monitors the

V DD/V DDA power supply and compares it to the V PVD threshold. This PVD offers 7 different

levels between 1.85 V and 3.05 V, chosen by software, with a step around 200 mV. An

interrupt can be generated when V DD/V DDA drops below the V PVD threshold and/or when

V DD/V DDA is higher than the V PVD threshold. The interrupt service routine can then generate

a warning message and/or put the MCU into a safe state. The PVD is enabled by software.

regulator

3.3.3 Voltage

The low density value line STM8L05xxx embeds an internal voltage regulator for generating

the 1.8 V power supply for the core and peripherals.

This regulator has two different modes:

?Main voltage regulator mode (MVR) for Run, Wait for interrupt (WFI) and Wait for event (WFE) modes.

?Low power voltage regulator mode (LPVR) for Halt, Active-halt, Low power run and Low power wait modes.

When entering Halt or Active-halt modes, the system automatically switches from the MVR

to the LPVR in order to reduce current consumption.

DocID023465 Rev 215/93

Functional overview STM8L051F3

16/93DocID023465 Rev 2

3.4 Clock management

The clock controller distributes the system clock (SYSCLK) coming from different oscillators

to the core and the peripherals. It also manages clock gating for low power modes and ensures clock robustness.

Features

?

Clock prescaler: to get the best compromise between speed and current consumption the clock frequency to the CPU and peripherals can be adjusted by a programmable prescaler.

?Safe clock switching: Clock sources can be changed safely on the fly in run mode through a configuration register.

?Clock management: To reduce power consumption, the clock controller can stop the clock to the core, individual peripherals or memory.

?

System clock sources: four different clock sources can be used to drive the system clock:–1-16 MHz High speed external crystal (HSE)–16 MHz High speed internal RC oscillator (HSI)–32.768 Low speed external crystal (LSE)–38 kHz Low speed internal RC (LSI)

?RTC clock sources: the above four sources can be chosen to clock the RTC whatever the system clock.

?

Startup clock: After reset, the microcontroller restarts by default with an internal 2 MHz clock (HSI/8). The prescaler ratio and clock source can be changed by the application program as soon as the code execution starts.

?Clock security system (CSS): This feature can be enabled by software. If a HSE clock failure occurs, it is automatically switched to HSI.

?

Configurable main clock output (CCO): This outputs an external clock for use by the application.

STM8L051F3Functional overview

1.The HSE clock source can be either an external crystal/ceramic resonator or an external source (HSE

bypass). Refer to Section HSE clock in the STM8L15x and STM8L16x reference manual (RM0031).

2.The LSE clock source can be either an external crystal/ceramic resonator or a external source (LSE

bypass). Refer to Section LSE clock in the STM8L15x and STM8L16x reference manual (RM0031).

DocID023465 Rev 217/93

Functional overview STM8L051F3

18/93DocID023465 Rev 2

3.5 Low power real-time clock

The real-time clock (RTC) is an independent binary coded decimal (BCD) timer/counter. Six byte locations contain the second, minute, hour (12/24 hour), week day, date, month, year, in BCD (binary coded decimal) format. Correction for 28, 29 (leap year), 30, and 31 day months are made automatically.

It provides a programmable alarm and programmable periodic interrupts with wakeup from Halt capability. ?

Periodic wakeup time using the 32.768 kHz LSE with the lowest resolution (of 61 μs) is from min. 122 μs to max. 3.9 s. With a different resolution, the wakeup time can reach 36 hours

?

Periodic alarms based on the calendar can also be generated from every second to every year

3.6 Memories

The low density value line STM8L05xxx devices have the following main features:?Up to 1 Kbyte of RAM

?

The non-volatile memory is divided into three arrays: –8 Kbytes of low-density embedded Flash program memory –256 bytes of Data EEPROM –

Option bytes

The EEPROM embeds the error correction code (ECC) feature.

The option byte protects part of the Flash program memory from write and readout piracy.

3.7 DMA

A 4-channel direct memory access controller (DMA1) offers a memory-to-memory and peripherals-from/to-memory transfer capability. The 4 channels are shared between the following IPs with DMA capability: ADC1, I2C1, SPI1, USART1, and the three timers.

3.8 Analog-to-digital converter

?12-bit analog-to-digital converter (ADC1) with 10 channels (including 1 fast channel)

and internal reference voltage

?Conversion time down to 1 μs with f SYSCLK = 16 MHz ?Programmable resolution ?Programmable sampling time

?Single and continuous mode of conversion

?Scan capability: automatic conversion performed on a selected group of analog inputs ?Analog watchdog ?

Triggered by timer

Note:

ADC1 can be served by DMA1.

DocID023465 Rev 219/93

STM8L051F3Functional overview

3.9 System configuration controller and routing interface

The system configuration controller provides the capability to remap some alternate functions on different I/O ports. TIM4 and ADC1 DMA channels can also be remapped.The highly flexible routing interface controls the routing of internal analog signals to ADC1 and the internal reference voltage V REFINT .

3.10 Timers

Low density value line STM8L05xxx devices contain two 16-bit general purpose timers (TIM2 and TIM3) and one 8-bit basic timer (TIM4).All the timers can be served by DMA1.

Table 2 compares the features of the advanced control, general-purpose and basic timers.

3.10.1 16-bit general purpose timers (TIM2, TIM3)

?16-bit autoreload (AR) up/down-counter

?7-bit prescaler adjustable to fixed power of 2 ratios (1…128)? 2 individually configurable capture/compare channels ?PWM mode

?Interrupt capability on various events (capture, compare, overflow, break, trigger)?

Synchronization with other timers or external signals (external clock, reset, trigger and enable)

3.10.2 8-bit basic timer (TIM4)

The 8-bit timer consists of an 8-bit up auto-reload counter driven by a programmable prescaler. It can be used for timebase generation with interrupt generation on timer overflow.

3.11 Watchdog timers

The watchdog system is based on two independent timers providing maximum security to

the applications.

Table 2. Timer feature comparison

Timer

Counter resolution Counter

type Prescaler factor

DMA1 request generation

Capture/compare

channels

Complementary

outputs

TIM216-bit up/down Any power of 2

from 1 to 128Yes

2

None

TIM3TIM4

8-bit

up

Any power of 2 from 1 to 32768

Functional overview STM8L051F3

20/93DocID023465 Rev 2

3.11.1 Window watchdog timer

The window watchdog (WWDG) is used to detect the occurrence of a software fault, usually

generated by external interferences or by unexpected logical conditions, which cause the application program to abandon its normal sequence.

3.11.2 Independent watchdog timer

The independent watchdog peripheral (IWDG) can be used to resolve processor

malfunctions due to hardware or software failures.

It is clocked by the internal LSI RC clock source, and thus stays active even in case of a CPU clock failure.

3.12 Beeper

The beeper function outputs a signal on the BEEP pin for sound generation. The signal is in the range of 1, 2 or 4 kHz.

3.13 Communication interfaces

3.13.1 SPI

The serial peripheral interfaces (SPI1) provide half/ full duplex synchronous serial

communication with external devices.?Maximum speed: 8 Mbit/s (f SYSCLK /2) both for master and slave ?Full duplex synchronous transfers

?Simplex synchronous transfers on 2 lines with a possible bidirectional data line ?Master or slave operation - selectable by hardware or software ?Hardware CRC calculation ?

Slave/master selection input pin

Note:

SPI1 can be served by the DMA1 Controller.

3.13.2 I 2C

The I 2C bus interface (I2C1) provides multi-master capability, and controls all I2C bus-specific sequencing, protocol, arbitration and timing.?Master, slave and multi-master capability

?Standard mode up to 100 kHz and fast speed modes up to 400 kHz ?7-bit and 10-bit addressing modes ?SMBus 2.0 and PMBus support ?

Hardware CRC calculation

Note:

I 2C1 can be served by the DMA1 Controller.

OB开发手册中文版

OB开发手册中文版

Contents [hide]1 简介 ? 1 简介 ? 1.1 开发概述 ? 1.2 开发方法 ? 1.3 组织开发工作 ? 1.4 标识符命名标准 ? 1.4.1 数据库元素 ? 1.4.2 MVC目录 ? 1.4.3 存储过程语法 ? 1.5 目录结构 ? 1.6 风格指南 ? 1.6.1 逻辑比较 ? 1.6.2 逗号分隔列表 ? 1.6.3 圆括号中的空格 ? 1.6.4 SELECT INTO和INSERT INTO ? 1.6.5 SQL关键字 ? 1.7 编译程序 ? 1.7.1 命令行编译任务 ? 1.7.2 开发环境 ? 1.7.3 生产环境 ? 1.8 从源代码构建 ? 1.8.1 安装Subversion ? 1.8.2 从Subversion中检出源代码 ? 1.8.3 快速构建指南 ? 1.9 集成开发环境 ? 2 Openbravo数据模型 ? 2.1 存储的数据库对象 ? 2.2 实体-关系(ER)图 ? 2.3 创建存储过程 ? 2.3.1 AD_PInstance和AD_PInstance_Para表 ? 2.3.2 存储过程的输入参数 ? 2.3.2.1 从AD_PInstance表中获取有用的信息 ? 2.3.2.2 AD_Update_PInstance存储过程 ? 2.3.2.3 例外和错误管理 ? 2.4 存储过程语法的建议 ? 2.4.1 通用规则 ? 2.4.1.1 游标 ? 2.4.1.2 数组 ? 2.4.1.3 ROWNUM ? 2.4.1.4 %ROWCOUNT ? 2.4.1.5 %ISOPEN,%NOTFOUND ? 2.4.2 表 ? 2.4.3 函数 ? 2.4.4 存储过程

PostgreSQL学习手册

tgreSQL学习手册(五) 函数和操作符 阿里云携手开源中国众包平台发布百万悬赏项目? 一、逻辑操作符: 常用的逻辑操作符有:AND、OR和NOT。其语义与其它编程语言中的逻辑操作符完全相同。 二、比较操作符: 下面是PostgreSQL中提供的比较操作符列表: 操作符描述 <小于 >大于 <=小于或等于 >=大于或等于 =等于 !=不等于 比较操作符可以用于所有可以比较的数据类型。所有比较操作符都是双目操作符,且返回boolean类型。除了比较操作符以外,我们还可以使用BETWEEN语句,如: a BETWEEN x AND y 等效于 a >= x AND a <= y a NOT BETWEEN x AND y 等效于 a < x OR a > y 三、数学函数和操作符: 下面是PostgreSQL中提供的数学操作符列表: 操作符描述例子结果 +加 2 + 35 -减 2 - 3-1 *乘 2 * 36 /除 4 / 22 %模 5 % 41 ^幂 2.0 ^ 3.08 |/平方根|/ 25.05 ||/立方根||/ 27.03 !阶乘 5 !120 !!阶乘!! 5120 @绝对值@ -5.05 &按位AND91 & 1511 |按位OR32 | 335

#按位XOR17 # 520 ~按位NOT~1-2 <<按位左移 1 << 416 >>按位右移8 >> 22 按位操作符只能用于整数类型,而其它的操作符可以用于全部数值数据类型。按位操作符还可以用于位串类型bit和bit varying, 下面是PostgreSQL中提供的数学函数列表,需要说明的是,这些函数中有许多都存在多种形式,区别只是参数类型不同。除非特别指明,任何特定形式的函数都返回和它的参数相同的数据类型。 函数返回类 型 描述例子结果 abs(x)绝对值abs(-17.4)17.4 cbrt(double)立方根cbrt(27.0)3 ceil(double/numeric)不小于参数的最小的整 数 ceil(-42.8)-42 degrees(double) 把弧度转为角度degrees(0.5)28.6478897565412 exp(double/numeric)自然指数exp(1.0) 2.71828182845905 floor(double/numeric)不大于参数的最大整数floor(-42.8)-43 ln(double/numeric)自然对数ln(2.0)0.693147180559945 log(double/numeric)10为底的对数log(100.0)2 log(b numeric,x numeric)numeric指定底数的对 数 log(2.0, 64.0) 6.0000000000 mod(y, x)取余数mod(9,4)1 pi() double"π"常量pi() 3.14159265358979 power(a double, b double)double求a的b次幂power(9.0, 3.0)729 power(a numeric, b numeric) numeric求a的b次幂power(9.0, 3.0)729 radians(double)double把角度转为弧度radians(45.0)0.785398163397448 random()double 0.0到1.0之间的随机 数值 random() round(double/numeric)圆整为最接近的整数round(42.4)42 round(v numeric, s int)numeric圆整为s位小数数字round(42.438,2)42.44 sign(double/numeric)参数的符号(-1,0,+1) sign(-8.4)-1 sqrt(double/numeric)平方根sqrt(2.0) 1.4142135623731 trunc(double/numeric)截断(向零靠近)trunc(42.8)42 trunc(v numeric, s int)numeric 截断为s小数位置的数 字 trunc(42.438,2)42.43 三角函数列表: 函数描述 acos(x)反余弦

PostgreSQL学习手册(PLpgSQL过程语言)

一、概述: PL/pgSQL函数在第一次被调用时,其函数内的源代码(文本)将被解析为二进制指令树,但是函数内的表达式和SQL命令只有在首次用到它们的时候,PL/pgSQL解释器才会为其创建一个准备好的执行规划,随后对该表达式或SQL命令的访问都将使用该规划。如果在一个条件语句中,有部分SQL命令或表达式没有被用到,那么PL/pgSQL解释器在本次调用中将不会为其准备执行规划,这样的好处是可以有效地减少为PL/pgSQL函数里的语句生成分析和执行规划的总时间,然而缺点是某些表达式或SQL命令中的错误只有在其被执行到的时候才能发现。 由于PL/pgSQL在函数里为一个命令制定了执行计划,那么在本次会话中该计划将会被反复使用,这样做往往可以得到更好的性能,但是如果你动态修改了相关的数据库对象,那么就有可能产生问题,如: CREATE FUNCTION populate() RETURNS integer AS $$ DECLARE -- 声明段 BEGIN PERFORM my_function(); END; $$ LANGUAGE plpgsql; 在调用以上函数时,PERFORM语句的执行计划将引用my_function对象的OID。在此之后,如果你重建了my_function函数,那么populate函数将无法再找到原有my_function函数的OID。要解决该问题,可以选择重建populate函数,https://www.wendangku.net/doc/db2763742.html,或者重新登录建立新的会话,以使PostgreSQL重新编译该函数。要想规避此类问题的发生,在重建my_function时可以使用CREATE OR REPLACE FUNCTION命令。 鉴于以上规则,在PL/pgSQL里直接出现的SQL命令必须在每次执行时均引用相同的表和字段,换句话说,不能将函数的参数用作SQL命令的表名或字段名。如果想绕开该限制,可以考虑使用PL/pgSQL 中的EXECUTE语句动态地构造命令,由此换来的代价是每次执行时都要构造一个新的命令计划。 使用PL/pgSQL函数的一个非常重要的优势是可以提高程序的执行效率,由于原有的SQL调用不得不在客户端与服务器之间反复传递数据,这样不仅增加了进程间通讯所产生的开销,而且也会大大增加网络IO的开销。 二、PL/pgSQL的结构: PL/pgSQL是一种块结构语言,函数定义的所有文本都必须在一个块内,其中块中的每个声明和每条语句都是以分号结束,如果某一子块在另外一个块内,那么该子块的END关键字后面必须以分号结束,不过对于函数体的最后一个END关键字,分号可以省略,如: [ <

PostgreSQL+Linux 从入门到精通培训文档 2命令

本章大纲 1. 如何访问命令行 2. 使用命令行下的工具 非编辑模式 进入编辑模式 3. 正则表达式、管道和I/O 重定向 4. 管理用户账户 5. 文件访问控制 6. 管理进程 1,如何访问命令行 1.1 本地命令行的访问 在图形界面中,访问命令行的方法:打开Terminal,Console。或者:Ctrl+Alt+F1 ~ F6 1.2 使用SSH 访问命令行 同上 2,使用命令行下的工具 2.1 使用硬链接

硬链接,指在同一个文件系统中,对inode的引用,只要文件上存在至少1个硬链接,就可以找到对应的inode。 [digoal@digoal01 ~]$ echo "abc" > ./a [digoal@digoal01 ~]$ stat a File: `a' Size: 4 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 656374 Links: 1 -- 硬链接数量 Access: (0664/-rw-rw-r--) Uid: ( 500/ digoal) Gid: ( 500/ digoal) Access: 2017-04-11 13:18:14.292848716 +0800 Modify: 2017-04-11 13:18:14.292848716 +0800 Change: 2017-04-11 13:18:14.292848716 +0800 创建硬链接 [digoal@digoal01 ~]$ ln -L ./a ./b [digoal@digoal01 ~]$ stat a File: `a' Size: 4 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 656374 Links: 2 Access: (0664/-rw-rw-r--) Uid: ( 500/ digoal) Gid: ( 500/ digoal) Access: 2017-04-11 13:18:14.292848716 +0800 Modify: 2017-04-11 13:18:14.292848716 +0800 Change: 2017-04-11 13:18:34.631855044 +0800 [digoal@digoal01 ~]$ stat b File: `b' Size: 4 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 656374 Links: 2 Access: (0664/-rw-rw-r--) Uid: ( 500/ digoal) Gid: ( 500/ digoal) Access: 2017-04-11 13:18:14.292848716 +0800 Modify: 2017-04-11 13:18:14.292848716 +0800 Change: 2017-04-11 13:18:34.631855044 +0800 删除一个硬链接,还能通过其他硬链接找到对应的inode。 [digoal@digoal01 ~]$ rm a rm: remove regular file `a'? y [digoal@digoal01 ~]$ cat b abc 2.2 归档和解压 常用的归档命令tar 归档-c (常用压缩库-j bz2, -z gzip) [digoal@digoal01 ~]$ tar -jcvf test.tar.bz2 b

PostgreSQL学习手册:SQL语言函数

PostgreSQL学习手册:SQL语言函数 一、基本概念: SQL函数可以包含任意数量的查询,但是函数只返回最后一个查询(必须是SELECT)的结果。在简单情况下,返回最后一条查询结果的第一行。如果最后一个查询不返回任何行,那么该函数将返回NULL值。如果需要该函数返回最后一条SELECT语句的所有行,可以将函数的返回值定义为集合,即SETOF sometype。 SQL函数的函数体应该是用分号分隔的SQL语句列表,其中最后一条语句之后的分号是可选的。除非函数声明为返回void,否则最后一条语句必须是SELECT。事实上,在SQL函数中,不仅可以包含SELECT查询语句,也可以包含INSERT、UPDATE和DELETE等其他标准的SQL 语句,但是和事物相关的语句不能包含其中,如BEGIN、COMMIT、ROLLBACK和SAVEPOINT 等。 CREATE FUNCTION命令的语法要求函数体写成一个字符串文本。通常来说,该文本字符串常量使用美元符($$)围住,如: CREATE FUNCTION clean_emp() RETURNS void AS $$ DELETE FROM emp WHERE salary < 0; $$ LANGUAGE SQL; 最后需要说明的是SQL函数中的参数,PostgreSQL定义$1表示第一个参数,$2为第二个参数并以此类推。如果参数是复合类型,则可以使用点表示法,即$https://www.wendangku.net/doc/db2763742.html,访问复合类型参数中的name字段。需要注意的是函数参数只能用作数据值,而不能用于标识符,如:INSERT INTO mytable VALUES ($1); --合法 INSERT INTO $1 VALUES (42); --不合法(表名属于标示符之一) 二、基本类型: 最简单的SQL函数可能就是没有参数且返回基本类型的函数了,如: CREATE FUNCTION one() RETURNS integer AS $$ SELECT 1 AS result; $$ LANGUAGE SQL; 下面的例子声明了基本类型作为函数的参数。 CREATE FUNCTION add_em(integer, integer) RETURNS integer AS $$ SELECT $1 + $2; $$ LANGUAGE SQL; # 通过select调用函数。 postgres=# SELECT add_em(1,2) AS answer; answer -------- 3 (1 row) 在下面的例子中,函数体内包含多个SQL语句,它们之间是用分号进行分隔的。CREATE FUNCTION tf1 (integer, numeric) RETURNS numeric AS $$ UPDATE bank SET balance = balance - $2 WHERE accountno = $1; SELECT balance FROM bank WHERE accountno = $1; $$ LANGUAGE SQL;

Sqoop官方中文手册

Sqoop中文手册 1. 概述 本文档主要对SQOOP的使用进行了说明,参考内容主要来自于Cloudera SQOOP的官方文档。为了用中文更清楚明白地描述各参数的使用含义,本文档几乎所有参数使用说明都经过了我的实际验证而得到。 2. codegen 将关系数据库表映射为一个java文件、java class类、以及相关的jar包, 1、将数据库表映射为一个Java文件,在该Java文件中对应有表的各个字段。 2、生成的Jar和class文件在metastore功能使用时会用到。 基础语句: sqoop codegen –connect jdbc:mysql://localhost:3306/hive –username root –password 123456 –table TBLS2

3. create-hive-table 生成与关系数据库表的表结构对应的HIVE表 基础语句: sqoop create-hive-table –connect jdbc:mysql://localhost:3306/hive -username root -password 123456 –table TBLS –hive-table h_tbls2 4. eval

可以快速地使用SQL语句对关系数据库进行操作,这可以使得在使用import这种工具进行数据导入的时候,可以预先了解相关的SQL语句是否正确,并能将结果显示在控制台。 查询示例: sqoop eval –connect jdbc:mysql://localhost:3306/hive -username root -password 123456 -query ―SELECT * FROM tbls LIMIT 10″ 数据插入示例: sqoop eval –connect jdbc:mysql://localhost:3306/hive -username root -password 123456 -e ―INSERT INTO TBLS2 VALUES(100,1375170308,1,0,‘hadoop‘,0,1,‘guest‘,‘MANAGED_TABLE‘,‘abc‘,‘ddd‘)‖ -e、-query这两个参数经过测试,比如后面分别接查询和插入SQL语句,皆可运行无误,如上。 5. export 从hdfs中导数据到关系数据库中 sqoop export –connect jdbc:mysql://localhost:3306/hive –username root –password 123456 –table TBLS2 –export-dir sqoop/test

GP简明使用手册

GP服务启停 su - gpadmin gpstart #正常启动 gpstop #正常关闭 gpstop -M fast #快速关闭 gpstop –r #重启 gpstop –u #重新加载配置文件 登陆与退出Greenplum #正常登陆 psql gpdb psql -d gpdb -h gphostm -p 5432 -U gpadmin #使用utility方式 PGOPTIONS="-c gp_session_role=utility" psql -h -d dbname hostname -p port #退出 在psql命令行执行\q 参数查询 psql -c 'SHOW ALL;' -d gpdb gpconfig --show max_connections 创建数据库 createdb -h localhost -p 5432 dhdw 创建GP文件系统 # 文件系统名 gpfsdw # 子节点,视segment数创建目录 mkdir -p /gpfsdw/seg1 mkdir -p /gpfsdw/seg2 chown -R gpadmin:gpadmin /gpfsdw # 主节点 mkdir -p /gpfsdw/master chown -R gpadmin:gpadmin /gpfsdw gpfilespace -o gpfilespace_config

gpfilespace -c gpfilespace_config 创建GP表空间 psql gpdb create tablespace TBS_DW_DATA filespace gpfsdw; SET default_tablespace = TBS_DW_DATA; 删除GP数据库 gpdeletesystem -d /gpmaster/gpseg-1 -f 查看segment配置 select * from gp_segment_configuration; 文件系统 select * from pg_filespace_entry; 磁盘、数据库空间 SELECT * FROM gp_toolkit.gp_disk_free ORDER BY dfsegment; SELECT * FROM gp_toolkit.gp_size_of_database ORDER BY sodddatname;日志 SELECT * FROM gp_toolkit.__gp_log_master_ext; SELECT * FROM gp_toolkit.__gp_log_segment_ext; 表描述 /d+ 表分析 VACUUM ANALYZE tablename; 表数据分布 SELECT gp_segment_id, count(*) FROM GROUP BY gp_segment_id; 表占用空间 SELECT relname as name, sotdsize/1024/1024 as size_MB, sotdtoastsize as toast, sotdadditionalsize as other FROM gp_toolkit.gp_size_of_table_disk as sotd, pg_class WHERE sotd.sotdoid = pg_class.oid ORDER BY relname;

H2Database中文教程(精编文档).doc

【最新整理,下载后即可编辑】 启动和使用H2管理系统 设置H2管理系统 通过JDBC连接到数据库 创建一个新的数据库 使用服务器模式 使用Hibernate 使用TopLink和Glassfish 使用EclipseLink 在WEB应用中使用数据库 CSV (逗号分隔文件)的支持 升级,备份,和恢复 命令行工具 使用OpenOffice基础框架 使用/ JNLP启动JAVA WEB 使用连接池 全文检索 用户自定义变量 日期和时间 使用Spring 使用和启动H2管理系统 H2管理系统让你能够通过一个浏览器对H2的SQL数据库进行管理操作。H2管理系统不仅可以连接H2数据库,也可以连接其他支持JDBC接口的数据库。

这是一个B/C/S应用,在服务器和浏览器上都要运行H2的管理程序。根据平台不同,H2管理系统支持多种启动应用的方式。在windows上有两种方式启动H2管理系统 方式一:单击[开始],[程序],[H2],和[H2 Console (Command Line)]。当使用SUN JDK1.5时,一个标题为'H2 Console'的窗口将弹出。当使用SUN JDK1.6时,一个数据库图标将被加入WINDOWS到系统托盘。如果既无窗口弹出也没有图标加入到系统托盘,很可能是你的JDK没有正确安装(如果确认自己的JDK 安装正确,可以尝试用另外一种方式启动控制台)。另外一个浏览器窗口将被打开,指向的URL是http://localhost:8082,是H2管理系统的登录页面。 方式二:打开文件浏览器,切换目录到h2/bin,双击运行h2.bat。一个控制台窗口将弹出,如果有问题,将有错误信息在这个窗口里显示。一个浏览器窗口将被打开,指向的URL是http://localhost:8082,是H2管理系统的登录页面。 其他操作系统启动H2管理系统 方式一:双击h2*.jar文件,如果.jar文件能正确的被java打开。

Postgresql配置文件

相比mysql单一的https://www.wendangku.net/doc/db2763742.html,f,postgresql的访问认证配置主要涉及到两个主要的配置文件:postgresql.conf和pg_hba.conf,本文从安全设置角度讲述这两个配置文件的配置选项。部分文字、样例摘抄自postgresql的中文手册。 postgresql.conf postgresql.conf包含了许多的选项,这些选项控制了postgresql.conf的方方面面,中间影响访问认证的选项是: unix_socket_group 设置Unix 域套接字的组所有人,(套接字的所有权用户总是启动postmaster 的用户)与UNIX_SOCKET_PERMISSIONS 选项一起使用可以给这种套接字类型增加额外的访问控制机制,缺省时是一个空字串,也就是使用当前用户的缺省的组,这个选项只能在服务器启动时设置。 unix_socket_permissions 给Unix 域套接字设置访问权限,Unix 域套接字使用通常的Unix 文件系统权限集。可选的值可以是一个chmod 和umask 系统调用可以接受的数字模式。(要使用客户化的八进制格式,该数字必须以0 (零)开头) 缺省权限是0777,意即任何人都可以联接,合理的选则可能是0770 (只有用户和组,参阅UNIX_SOCKET_GROUP)和0700 (只有用户)。(请注意对于Unix 套接字而言,实际上只有写权限有意义,而且也没有办法设置或者取消读或执行权限) 这个选项只能在服务器启动时设置。 pg_hba.conf是设置访问认证的主要文件,格式为每条记录一行,每行指定一条访问认证。设定一条访问认证包含了7个部分:连接方式(type)、数据库(database)、用户名(user)、ip地址(ip-address)、子网掩码(ip-mask)、认证方法(authentication method)、认证配置(authentication-option),以下是这7个部分的详细说明: 连接方式(type) 连接方式共有三种:local、host、hostssl local 这条记录匹配通过Unix 域套接字进行的联接企图,没有这种类型的记录,就不允许Unix 域套接字的联接。 host

PostgreSQL数据库配置参数详解

十章数据库参数 PostgresSQL提供了许多数据库配置参数,本章将介绍每个参数的作用和如何配置每一个参数。 10.1 如何设置数据库参数 所有的参数的名称都是不区分大小写的。每个参数的取值是布尔型、整型、浮点型和字符串型这四种类型中的一个,分别用boolean、integer、floating point和string表示。布尔型的值可以写成ON、OFF、TRUE、FALSE、YES、NO、1和0,而且不区分大小写。 有些参数用来配置内存大小和时间值。内存大小的单位可以是KB、MB和GB。时间的单位可以是毫秒、秒、分钟、小时和天。用ms表示毫秒,用s表示秒,用min表示分钟,用h表示小时,用d表示天。表示内存大小和时间值的参数参数都有一个默认的单位,如果用户在设置参数的值时没有指定单位,则以参数默认的单位为准。例如,参数shared_buffers 表示数据缓冲区的大小,它的默认单位是数据块的个数,如果把它的值设成8,因为每个数据块的大小是8KB,则数据缓冲区的大小是8*8=64KB,如果将它的值设成128MB,则数据缓冲区的大小是128MB。参数vacuum_cost_delay 的默认单位是毫秒,如果把它的值设成10,则它的值是10毫秒,如果把它的值设成100s,则它的值是100秒。 所有的参数都放在文件postgresql.conf中,下面是一个文件实例: #这是注释 log_connections = yes log_destination = 'syslog' search_path = '"$user", public' 每一行只能指定一个参数,空格和空白行都会被忽略。“ #”表示注释,注释信息不用单独占一行,可以出现在配置文件的任何地方。如果参数的值不是简单的标识符和数字,应该用单引号引起来。如果参数的值中有单引号,应该写两个单引号,或者在单引号前面加一个反斜杠。 一个配置文件也可以包含其它配置文件,使用include指令能够达到这个目的,例如,假设postgresql.conf文件中有下面一行: include ‘my.confg’

Npgsql - 用户手册

Npgsql: 用户的手册 Copyright ?The Npgsql Development Team Last update: $Date: 2009/12/20 02:33:47 $ by $Author: fxjr $ Category: External documentation Intended Audience: Npgsql Users 1. What is Npgsql? Npgsql 是一个.net的资料提供者为postgresql的数据库服务器 它允许一个.net客户端应用程序(控制台,WinForms,ASP的。网络、网络服务…)发送和接收数据与postgresql的服务器。它正在积极开发基于指南规定在.net文档。 2. How to get and compile Npgsql 如何获得和编译Npgsql 2.1 Binary package 二进制包 你可以下载Npgsql编译为MS . 在里面编写.net的项目。 这个包裹里,你会发现下面的目录的布局。 Npgsql/bin/docs - Documentation Npgsql/bin/docs/apidocs - API Documentation Npgsql/bin/ms1.1 - Npgsql compiled for https://www.wendangku.net/doc/db2763742.html, 1.1 Npgsql/bin/mono - Npgsql compiled for Mono As soon as Npgsql is released on other platforms/versions, they will be added accordingly to this layout. 2.2 Installing binary package 安装二进制包 为了查找到。net运行时,文件Npgsql.dll必须放置在你的应用程序目录——除非你指定另一个目录作为通往私营成分通过一个配置文件(使用探测单元)。请看看。net除有关如何运行(位于)总成,被载入。确切地说,前面可以称为”通往私人组件" 在ASP。网络和网络服务的应用程序中,必须有一个叫做“bin”的应用与https://www.wendangku.net/doc/db2763742.html,目录. 举例来说,如果应用程序目录被称为“ASPNETApplication”,然后Npgsql.dll和Mono.Security.dll必须放置在“ASPNETApplication \bin”的目录. 如果这些文件是不正确的目录,你可以看到编译器生成错误代码,使用Npgsql类。 或者,你可以把Npgsql装配在解决。自从版本0.4,Npgsql强烈签字——这意味着你可以用“gacutil "安装它。 下列命令: gacutil - Npgsql.dll 请参阅“安装装配在全球缓存汇编”部分的单据MSDN来获得更多信息.利用gac的意义,你应该充分理解,沿着这条路。 注意,放置在……要求Npgsql设计时间支持.net可视化工作室。 (Npgsql编制单声道不需要Mono.Security.dll作为已经融入单声道运行。) 一旦你拷贝或设置组件,你准备去试试这个例子——跳转到section 3. 2.3 Getting Npgsql from CVS 获得Npgsql到CVS 让Npgsql到CVS,使用下列资料储存在你的客户信息 Server: https://www.wendangku.net/doc/db2763742.html, Repository: /cvsroot/npgsql Module name: Npgsql2 User: anonymous Password:

SQLite学习手册 中文全本

SQLite学习手册 内容收集自网络 整理: zhoushuangsheng@https://www.wendangku.net/doc/db2763742.html, 新浪微博:@_Nicky 开篇 一、简介: SQLite是目前最流行的开源嵌入式数据库,和很多其他嵌入式存储引擎相比(NoSQL),如BerkeleyDB、MemBASE等,SQLite可以很好的支持关系型数据库所具备的一些基本特征,如标准SQL语法、事务、数据表和索引等。事实上,尽管SQLite拥有诸多关系型数据库的基本特征,然而由于应用场景的不同,它们之间并没有更多的可比性。 下面我们将列举一下SQLite的主要特征: 1. 管理简单,甚至可以认为无需管理。 2. 操作方便,SQLite生成的数据库文件可以在各个平台无缝移植。 3. 可以非常方便的以多种形式嵌入到其他应用程序中,如静态库、动态库等。 4. 易于维护。 综上所述,SQLite的主要优势在于灵巧、快速和可靠性高。SQLite的设计者们为了达到这一目标,在功能上作出了很多关键性的取舍,与此同时,也失去了一些对RDBMS关键性功能的支持,如高并发、细粒度访问控制(如行级锁)、丰富的内置函数、存储过程和复杂的SQL语句等。正是因为这些功能的牺牲才换来了简单,而简单又换来了高效性和高可靠性。 二、SQLite的主要优点: 1. 一致性的文件格式: 在SQLite的官方文档中是这样解释的,我们不要将SQLite与Oracle或PostgreSQL去比较,而是应该将它看做fopen和fwrite。与我们自定义格式的数据文件相比,SQLite不仅提供了很好的移植性,如大端小端、32/64位等平台相关问题,而且还提供了数据访问的高效性,如基于某些信息建立索引,从而提高访问或排序该类数据的性能,SQLite提供的事务功能,也是在操作普通文件时无法有效保证的。 2. 在嵌入式或移动设备上的应用: 由于SQLite在运行时占用的资源较少,而且无需任何管理开销,因此对于PDA、智能手机等移动设备来说,SQLite的优势毋庸置疑。

PostgreSQL数据库学习手册之libpq

PostgreSQL数据库学习手册之libpq - C 库--介绍(转)[@more@] Chapter 1. libpq - C 库 Table of Contents 1.1. 介绍 1.2. 数据库联接函数 1.3. 命令执行函数 1.3.1. 主过程 1.3. 2. 为包含在 SQL 查询中逃逸字串 1.3.3. 逃逸包含在 SQL 查询中的二进制字串 1.3.4. 检索 SELECT 的结果信息 1.3.5. 检索 SELECT 结果数值 1.3.6. 检索非-SELECT 结果信息 1.4. 异步查询处理 1.5. 捷径接口 1.6. 异步通知 1.7. 与 COPY 命令相关的函数 1.8. libpq 跟踪函数 1.9. libpq 控制函数 1.10. 环境变量 1.11. 文件 1.1 2. 线程特性 1.13. 制作 Libpq 程序 1.14. 例子程序 1.1. 介绍 libpq 是 PostgreSQL的 C 应用程序员的接口. libpq 是一套允许客户程序向 PostgreSQL 后端服务进程发送查询并且获得查询返回的库过程. libpq 同时也是其他几个 PostgreSQL 应用接口下面的引擎,包括 libpq++ (C++), libpgtcl(Tcl),Perl,和 ecpg.所以如果你使用这些软件包, libpq某些方面的特性会对你非常重要. 本节末尾有三个小程序显示如何利用 libpq书写程序.在下面目录里面有几个完整的 libpq 应用的例子:src/test/examples src/bin/psql 使用 libpq 的前端程序必须包括头文件 libpq-fe.h 并且必须与 libpq 库链接. PostgreSQL数据库学习手册之libpq-C库---数据库联接函数(转)[@more@] 1.2. 数据库联接函数 下面的过程处理与 PostgreSQL 后端服务器联接的事情.一个应用程序一次可以与多个后端建立联接.(这么做的原因之一是访问多于一个数据库.)每个连接都是用一个从PQconnectdb()或PQsetdbLogin() 获得的PGconn对象表示.注意,这些函数总是返回一个非空的对象指针,除非存储器少得连个PGconn对象都分配不出来.在把查询发送给联接对象之前,可以调用PQstatus 函数来检查一下联接是否成功. * PQconnectdb 与后端数据库服务器建立一个新的联接. PGconn *PQconnectdb(const char *conninfo)

PostgreSQL部署文档

yum安装PostgreSQL 下载PostgreSQL源: rpm -Uvh https://https://www.wendangku.net/doc/db2763742.html,/pub/repos/yum/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-3.noarch.rpm 登录官网,选择适合自己的版本,本文选择的是PostgreSQL 9.4对应的CentOS7-x86_64版本。 执行安装命令: yum install postgresql94-server postgresql94-contrib 验证是否安装成功: rpm -aq| grep postgres 执行结果如下: postgresql94-libs-9.4.12-1PGDG.rhel7.x86_64 postgresql94-9.4.12-1PGDG.rhel7.x86_64 postgresql94-server-9.4.12-1PGDG.rhel7.x86_64 postgresql94-contrib-9.4.12-1PGDG.rhel7.x86_64 说明正确安装。 初始化数据库 /usr/pgsql-9.4/bin/postgresql94-setup initdb 一定要先初始化数据库,否则启动的时候会报如下错误: postgresql-check-db-dir[2994]: "/var/lib/pgsql/data"is missing or empty. postgresql-check-db-dir[2994]: Use"postgresql-setup initdb"to initialize the database cluster. 启动服务并设置为开机启动 systemctl enable postgresql-9.4 systemctl start postgresql-9.4

PostgreSQL注常见问题入总结

日本是一个多么让人联想翩翩浮想连连的词语,为啥我们要搞日本的大学捏?原因很简单,我们都爱日本妹子 国外的网站也不是坚不可摧,看完本系列文章你会发现,什么高深黑客技术,什么日本名牌大学的网站,也不过如此。都是五分钟从前台到服务器的货。 日本大学入侵系列篇章: 1) 《系列1之日本京都同志社大学 - php注入点写webshell,linux最简单提权》 2) 《系列2之日本共立女子大学 - 解决PostgreSQL连接问题完成脱众女子内裤》 3) 《系列3之日本东京大学 - PostgreSQL注入常见问题总结》 作者:YoCo Smart 来自:Silic Group Hacker Army https://www.wendangku.net/doc/db2763742.html, 本文基于《PostgreSQL注入语法指南》而写,首先我们先来总结常见问题,常见问题有这样几个 如何判断数据库使用了PostgreSQL数据库,字段数和字段间编码问题,GPC为on时的字符型字段问题,注释符问题。我们一个一个讲 1) 如何判断php搭配数据库为PostgreSQL 我们假设一个php+PostgreSQL并且开启了错误回显的网站有一个注入点,我们在 xx.php?id=n后面加单引号',它的回显将会是这样的: Warning: pg_query() [function.pg-query]: Query failed: ERROR: unterminated quoted string at or near "'" LINE 1: select * from now where no = 111' ^ in /home/sites/web/school/detail.php on line 307 有这样几个关键字可以判断数据库为PostgreSQL: 操作PostgreSQL的函数pg_query() 关键字function.pg-query中的pg 看熟了MySQL的错误回显,有没有发现这个unterminated quoted string at or near不是MySQL的?MySQL的错误回显和这个区别太大了 2) 字段数和字段间编码问题 我们首先将上面的注入点order by 2可以确认now数据表的字段数大于2,当我们order by 2000的时候,显然不可能有那个表段中有2000条数据,当然会出错 Warning:pg_query() [function.pg-query]: Query failed: ERROR: ORDER BY position 2000 is not in select list in /home/sites/web/school/detail.php on line 307 这样大致可以确认可以猜出正确的字段数了。假设字段数为14,那么我们按照MySQL的步骤 1.xx.php?id=0+union+select+1,2,3,4,5,6,7,8,9,10,11,12,13,14 复制代码 这句没问题吧?但是它99%概率会出问题了:

PostgresXL使用说明文档

Postgres-XL使用说明文档 一、知识点介绍 Postgres-XL是一个基于PostgreSQL数据库的横向扩展开源SQL数据库集群,XL代表eXtensible Lattice,即可扩展的PG“格子”之意,以下简称PGXL。官方称其既适合写操作压力较大的OLTP1应用,又适合读操作为主的大数据应用。它的前身是Postgres-XC(简称PGXC),PGXC是在PG的基础上加入了集群功能,主要适用于OLTP2应用;PGXL是在PGXC的基础上的升级产品,加入了一些适用于OLAP应用的特性,如Massively Parallel Processing (MPP) 特性。通俗的说PGXL的代码是包含PG代码的,使用PGXL安装PG集群并不需要单独安装PG。 总体感觉PGXL这款工具还是相当成熟的,有官方网站,文档也比较完善,也有商业公司2ndQuadrant在支持。 上面这张图就是PGXL集群的架构图,来自官方网站。所有节点中分为三种角色:GTM (全局事务管理器)、Coordinator(协调器)和Datanode(数据节点)。需要注意一点是图中 1OLTP过程(On-Line Transaction Processing),也称为面向交易的处理过程,其基本特征是前台接收的用户数据可以立即传送到计算中心进行处理,并在很短的时间内给出处理结果,是对用户操作快速响应的方式之一。OLTP系统强调数据库内存效率,强调内存各种指标的命令率,强调绑定变量,强调并发操作; 2OLAP,也叫联机分析处理(On-line Analytical Processing)系统,有的时候也叫DSS 决策支持系统,就是我们说的数据仓库。在这样的系统中,语句的执行量不是考核标准,因为一条语句的执行时间可能会非常长,读取的数据也非常多。所以,在这样的系统中,考核的标准往往是磁盘子系统的吞吐量(带宽),如能达到多少MB/s的流量。OLAP系统则强调数据分析,强调SQL执行市场,强调磁盘I/O,强调分区等。

相关文档